wiki:Implementation Brainstorm

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

--

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

   def _getProperty():
       # something neo4j-ish

   def _hasProperty():
       Bla

   def _linkIterator(self, linktype):
       # returns an iterator over edges
       Bla

   def _connectToNewVertex(self, connectiontype, connectionproperties, vertexclass …)
       Bla

   def _connectToExistingVertex(self, other, connectiontype, connectionproperties)
       Bla

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

    def getStartVertex(self):
         Bla

    def getEndVertex(self):
         Bla

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 ContentlessNode(Vertex):
    pass

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

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

    def addLabel(self, content, language, branch):
         self._connectToNewVertex('has-label', {'branch': branch}, …)

class ContentNode(Vertex):
    # routines to deal with rfc-822-like data
    pass

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()