You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-dev@lucene.apache.org by Bill Janssen <ja...@parc.com> on 2009/02/27 21:11:01 UTC

wrapping template types; neo4j

I'm not sure enums are high-priority, but comprehending template types
seems to be useful -- and perhaps vital going forward.  As you say, the
Lucene community is moving in this direction.

For the moment with neo4j, I've added a concrete type which instantiates
the Java interface, and packaged that with the other jar files.  That
makes it reasonably Pythonic to generate instances, but I've also
suggested to the neo4j project that they include this class to their
codebase, so that neo4j can just be wrapped and used out-of-the-box.
Since this (making neo4j work with JCC) is a "major" priority issue in
the neo4j bug-tracker, I have hopes it may happen.

Bill

Re: wrapping template types; neo4j

Posted by Andi Vajda <va...@apache.org>.
On Feb 27, 2009, at 19:05, Bill Janssen <ja...@parc.com> wrote:

> Andi Vajda <va...@apache.org> wrote:
>
>>> For instance, the org.neo4j.api.core.Node
>>> class doesn't have the vital method  
>>> "hasRelationship(RelationshipType...)".
>>> In fact, it doesn't seem to have a number of methods, like
>>> "Iterable<Relationship> getRelationships()".
>>>
>>> So, this is (I suppose) a variant of the Java 5 stuff not being
>>> supported by PyLucene.
>>>
>>> Might be nice to have JCC fail more obviously in this case...
>>
>> No, this is different. It's not related to these Java 1.5 features.
>>
>> It's because java.lang.Iterable is not 'known' to that JCC invocation
>> by default.
>
> Should have known it was my fault :-).  But what about "..."?
> That's used in hasRelationship(), which is kind of vital.

Maybe you didn't see that message yet but ... works as expected. A  
wrapper for a method taking an array of the corresponding type is  
generated.

Andi..

>
>
> Bill

Re: wrapping template types; neo4j

Posted by Andi Vajda <va...@apache.org>.
On Feb 28, 2009, at 19:57, Bill Janssen <ja...@parc.com> wrote:

> Andi Vajda <va...@apache.org> wrote:
>
>> On Feb 27, 2009, at 19:30, Bill Janssen <ja...@parc.com> wrote:
>>
>>> Ah, I see hasRelationship is already there.  The trick which I was
>>> missing is that you need to invoke it with a list of  
>>> RelationshipType
>>> values, not just a single value.
>>
>> Yes, ... becomes an array.
>>
>> Andi..
>
> That's reasonable, but somewhat un-Pythonic.  Be nice if it mapped  
> to a
> Python varargs call...  Something for the wish list, though I think
> template support is more important.

Yep, I'd expect this to appear with Java 1.5 feature support.

Andi..

>
>
> Bill

Re: wrapping template types; neo4j

Posted by Bill Janssen <ja...@parc.com>.
Andi Vajda <va...@apache.org> wrote:

> On Feb 27, 2009, at 19:30, Bill Janssen <ja...@parc.com> wrote:
> 
> > Ah, I see hasRelationship is already there.  The trick which I was
> > missing is that you need to invoke it with a list of RelationshipType
> > values, not just a single value.
> 
> Yes, ... becomes an array.
> 
> Andi..

That's reasonable, but somewhat un-Pythonic.  Be nice if it mapped to a
Python varargs call...  Something for the wish list, though I think
template support is more important.

Bill

Re: wrapping template types; neo4j

Posted by Andi Vajda <va...@apache.org>.
On Feb 27, 2009, at 19:30, Bill Janssen <ja...@parc.com> wrote:

> Ah, I see hasRelationship is already there.  The trick which I was
> missing is that you need to invoke it with a list of RelationshipType
> values, not just a single value.

Yes, ... becomes an array.

Andi..

>
>
> Bill

Re: wrapping template types; neo4j

Posted by Bill Janssen <ja...@parc.com>.
Ah, I see hasRelationship is already there.  The trick which I was
missing is that you need to invoke it with a list of RelationshipType
values, not just a single value.

Bill

Re: wrapping template types; neo4j

Posted by Bill Janssen <ja...@parc.com>.
Andi Vajda <va...@apache.org> wrote:

> > For instance, the org.neo4j.api.core.Node
> > class doesn't have the vital method "hasRelationship(RelationshipType...)".
> > In fact, it doesn't seem to have a number of methods, like
> > "Iterable<Relationship> getRelationships()".
> >
> > So, this is (I suppose) a variant of the Java 5 stuff not being
> > supported by PyLucene.
> >
> > Might be nice to have JCC fail more obviously in this case...
> 
> No, this is different. It's not related to these Java 1.5 features.
> 
> It's because java.lang.Iterable is not 'known' to that JCC invocation
> by default.

Should have known it was my fault :-).  But what about "..."?
That's used in hasRelationship(), which is kind of vital.

Bill

Re: wrapping template types; neo4j

Posted by Andi Vajda <va...@apache.org>.
On Fri, 27 Feb 2009, Andi Vajda wrote:

>
> If you add --package java.lang to your jcc invocation, the getRelationShips() 
> methods do get wrapped.
>
> As suspected, the pre-1.5 building blocks theory seems to be at work here.
> For example, the getRelationShips(RelationShipType... types) method gets 
> wrapped as taking a RelationShipType array.
>
> java::lang::Iterable Node::getRelationships(const 
> JArray<org::neo4j::api::core::RelationshipType>& a0) const
> {
>    return java::lang::Iterable(env->callObjectMethod(this$, 
> mids$[mid_getRelationships_5b47f265], a0.this$));
> }

In other words, JCC wraps these methods fine but loses the generic 
information. In Python, the invocation is going to be returning an Iterable 
of Object, not RelationShip as expected if JCC was heeding the generic 
annotations.

By the way, the Iterator returned from Iterable's iterator method has the 
same issue but it should still appear as a Python iterator nonetheless; you 
can pass it to list() or use it in a straightforward for loop, etc...

   for relationship in node.getRelationShips([types, ...]).iterator():
       ...

Andi..

Re: wrapping template types; neo4j

Posted by Andi Vajda <va...@apache.org>.
If you add --package java.lang to your jcc invocation, the 
getRelationShips() methods do get wrapped.

As suspected, the pre-1.5 building blocks theory seems to be at work here.
For example, the getRelationShips(RelationShipType... types) method gets 
wrapped as taking a RelationShipType array.

java::lang::Iterable Node::getRelationships(const JArray<org::neo4j::api::core::RelationshipType>& a0) const
{
     return java::lang::Iterable(env->callObjectMethod(this$, mids$[mid_getRelationships_5b47f265], a0.this$));
}

Cool :)

Andi..

Re: wrapping template types; neo4j

Posted by Andi Vajda <va...@apache.org>.
On Fri, 27 Feb 2009, Bill Janssen wrote:

> Actually, the wrapping of neo4j doesn't work with the latest JCC -- it
> just doesn't fail obviously.  However, some vital methods are not
> produced for several classes.  For instance, the org.neo4j.api.core.Node
> class doesn't have the vital method "hasRelationship(RelationshipType...)".
> In fact, it doesn't seem to have a number of methods, like
> "Iterable<Relationship> getRelationships()".
>
> So, this is (I suppose) a variant of the Java 5 stuff not being
> supported by PyLucene.
>
> Might be nice to have JCC fail more obviously in this case...

No, this is different. It's not related to these Java 1.5 features.

It's because java.lang.Iterable is not 'known' to that JCC invocation by 
default.

As documented [1], to avoid runaway transitive closures, JCC will only wrap 
methods where all parameters and return type are part of the requested set 
of classes, jars or packages specified on the command line (see [1]).

A few core classes are 'known' by default, but java.lang.Iterable is not.
If you add --package java.lang to the invocation, these methods appear in 
the wrappers as expected.

You'd probably ask for --package java.lang to be part of the defaults and 
it's a reasonable request at first glance. In JCC's cpp.py, there is 
currently a list of classes considered always 'known' to JCC. 
java.lang.Iterable is not one of them. Maybe, again, it's because Iterable 
appeared in Java 1.5 (unsure).

Andi..

[1] http://lucene.apache.org/pylucene/jcc/documentation/readme.html#use


Re: wrapping template types; neo4j

Posted by Bill Janssen <ja...@parc.com>.
Actually, the wrapping of neo4j doesn't work with the latest JCC -- it
just doesn't fail obviously.  However, some vital methods are not
produced for several classes.  For instance, the org.neo4j.api.core.Node
class doesn't have the vital method "hasRelationship(RelationshipType...)".
In fact, it doesn't seem to have a number of methods, like
"Iterable<Relationship> getRelationships()".

So, this is (I suppose) a variant of the Java 5 stuff not being
supported by PyLucene.

Might be nice to have JCC fail more obviously in this case...

Bill