25 |
from com.hp.hpl.mesa.rdf import jena |
from com.hp.hpl.mesa.rdf import jena |
26 |
|
|
27 |
class Cmp(java.util.Comparator): |
class Cmp(java.util.Comparator): |
28 |
|
def __init__(self, get): |
29 |
|
self.get = get |
30 |
|
|
31 |
def compare(self, r1, r2): |
def compare(self, r1, r2): |
32 |
if (not r1) or (not r2): |
if (not r1) or (not r2): |
33 |
raise java.lang.NullPointerException("r1=%r, r2=%r" % (r1, r2)) |
raise java.lang.NullPointerException("r1=%r, r2=%r" % (r1, r2)) |
34 |
|
|
35 |
# Nodes are compared by order of index: |
# Nodes are compared by order of subject's index: |
36 |
# n[4] > n[2], n[7] > n[4] etc. |
# n[4] > n[2], n[7] > n[4] etc. |
37 |
return n.index(r1) - n.index(r2) |
return n.index(self.get(r1)) - n.index(self.get(r2)) |
38 |
|
|
39 |
|
subjectCmp = Cmp(lambda stmt: stmt.getSubject()) |
40 |
|
objectCmp = Cmp(lambda stmt: stmt.getObject()) |
41 |
|
|
42 |
def list(set): |
def list(set): |
43 |
l = []; i = set.iterator() |
l = []; i = set.iterator() |
62 |
for i in range(3,10): |
for i in range(3,10): |
63 |
n[2].addProperty(p, n[i]) |
n[2].addProperty(p, n[i]) |
64 |
|
|
65 |
c = gzz.loom.Cursor(Cmp()) |
c = gzz.loom.Cursor(subjectCmp, objectCmp) |
66 |
|
|
67 |
|
|
68 |
def testGetConnections(): |
def testGetConnections(): |