Version 5 (modified by rob.hooft@…, 3 years ago)

class Vertex(object):
    # all neo4j node code is concentrated here.
    def __init__(self, neo4jnode):
        self.node = neo4jnode

    def _getProperty(self, propertyname):
        # something neo4j-ish
        # raises exception(?) if property does not exist
        pass

    def _hasProperty(self, propertyname):
        pass

    def _linkIterator(self, linktype):
        # returns an iterator over edges. 
        # An iterator over edges is better than a collection of 
        # edges as a primitive, since it does not store everything at once.
        pass

    def _connectToNewVertex(self, direction,
                                  edgeclass, edgeproperties, 
                                  vertexclass, vertexproperties)
        pass

    def _connectToExistingVertex(self, other, direction,
                                       connectiontype, connectionproperties)
        pass

class Edge(object):
    # all neo4j relation code is concentrated here
    def __init__(self, neo4jrelation):
        self.relation = neo4jrelation

    def _getProperty(self, propertyname):
        # something neo4j-ish
        # raises exception(?) if property does not exist
        pass

    def _hasProperty(self, propertyname):
        pass

    def _getStartVertex(self):
        pass

    def _getEndVertex(self):
        pass

class LabelEdge(Edge):
    def getStartVertex(self):
         sv = Edge.getStartVertex(self)
         assert sv._hasProperty('uuid')
         return (Concept)sv

    def getBranch(self):
        return self._getProperty('branch')

class User(Singleton):
    branch = 'community'

class ContentlessNode(Vertex):
    pass

class Concept(ContentlessNode):
    def __init__(self, neo4jnode):
         Vertex.__init__(self, neo4jnode)
         assert self._hasProperty('uuid')

    def getLabelEdgeIterator(self):
       return self._linkiterator('has-label')

    def addLabel(self, content, language):
         self._connectToNewVertex(LabelEdge, …)

    def getUuid(self):
        return self._getProperty('uuid')

# Some re-used strings

EMPTY = ''
PLAINTEXT = 'text/plain' 
EIGHTBIT = '8bit'
UTF8 = 'utf-8'

class ContentNode(Vertex):
    # routines to deal with rfc-822-like data
    def getContent(self):
        if self._hasProperty('content'):
            return self._getProperty('content')
        else:
            return EMPTY

    def getContentType(self):
        if self._hasProperty('content-type'):
            return self._getProperty('content-type')
        else:
            return PLAINTEXT

    def getContentEncoding(self):
        if self._hasProperty('content-encoding'):
            return self._getProperty('content-encoding')
        elif self.getContentType() == PLAINTEXT:
            return UTF8
        else:
            return EIGHTBIT

    def getContentLanguage(self):
        return self._getProperty('content-language')

class Label(ContentNode):
    defaultContentEncoding = 'utf-8'
    pass

def ConceptIterator():
    r = neo4j.root()
    r2 = r.traverse('_':'concepts')
    for link in r2.getLinks('is-a'):
        yield link.start()

def ConceptByName(label, language):
    n=neo4j.lucene.searchNode({'content':label, 'content-language':language)
    return Concept(n)

def PrintWikiPage(Concept):
    print Concept.preferredLabel(currentLanguage)
    for labeledge in Concept.iterateLabelEdges()
	label = labeledge.getEndNode()
        print label.getLanguage(), labeledge.getBranch(), label.content()