wiki:Implementation Brainstorm

This design is obsolete. We will do it differently.

EMPTY = ''
PLAINTEXT = 'text/plain' 
EIGHTBIT = '8bit'
UTF8 = 'utf-8'
DIRECTION = {'incoming':0, 'outgoing':1}

class Branch(string):
    # For now, just a string. Will be smarter later.
    pass

class Language(string):
    # For now, just a string. Will be smarter later.
    pass

class Session(object):
    language = ''
    user = ''
    branch = ''

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, direction, 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,
                                  edgetype, edgeproperties, 
                                  vertexproperties)
        pass

    def _connectToExistingVertex(self, other, direction,
                                       edgetype, edgeproperties)
        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):
         # Check, and cast.
         sv = self._getStartVertex()
         assert sv._hasProperty('uuid')
         return (ConceptVertex)sv

    def getEndVertex(self):
        # Check, and cast
        ev = self._getEndVertex()
        assert ev._hasProperty('content')
        return (LabelVertex)ev

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

class User(Singleton):
    branch = Branch('community')

class ContentlessVertex(Vertex):
    pass

class ConceptVertex(ContentlessVertex):
    def __init__(self, neo4jnode):
         Vertex.__init__(self, neo4jnode)
         assert self._hasProperty('uuid')

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

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

    # In second Phase
    def addLabel(self, content, language):
         self._connectToNewVertex(OUTGOING, LabelEdge, …)

class ContentVertex(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):
    pass

class Notation(ContentNode):
    def getLanguage(self):
        raise TypeError("Notation is language-independent")

    def getContext(self):
        return self._getProperty('context')

class Definition(ContentNode):
    pass

class GraphHandler:
    def ConceptIterator(self):
        r = self.getGraphRoot()
        r2 = r.traverse('_':'concepts')
        for link in r2.getLinks('is-a'):
            yield link.start()

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

    def getConceptByUUID(self, uuid):
        pass

    def getConceptByNotation(self, context, dbid):
        pass

def PrintWikiPage(Concept):
    print Concept.preferredLabel(currentLanguage)
    for labeledge in Concept.iterateLabelEdges()
	label = labeledge.getEndNode()
        print label.getLanguage(), labeledge.getBranch(), label.content()
Last modified 8 years ago Last modified on Jul 13, 2011, 1:48:41 PM