Exemplo n.º 1
0
def fuzzyTextMatchElseNew(graph, default_graphs, basens, ctype, attrs=[], string='', lang='nl', max_diff=.4, interactive=True,\
                          align='off', endpoint=''):
    exnode = None
    if align == 'local' or align == 'global' or align == 'both':
        (exnode, source) = fuzzyTextMatch(graph, default_graphs, ctype, attrs, string, max_diff, interactive, align, endpoint)

    # guarantee uniqueness within a converted graph
    if source == graph:
        return exnode

    # else ensure complete graph by using 'sameAs'
    nss = dict(ns for ns in graph.namespace_manager.namespaces())
    hid = hf.genHash(None, None, [], salt=string + ctype.toPython())
    node = hf.getNode(graph, hid)
    if node is None:
        node = rdflib.URIRef(basens + hid)
        hf.addType(graph, node, ctype)
        label = rdflib.Literal(string, datatype=rdflib.URIRef(nss['xsd'] + 'string'))
        hf.addLabel(graph, node, label, lang)

    if exnode is not None and exnode.toPython() != node.toPython():
        hf.addProperty(graph, node, exnode, rdflib.URIRef(nss['rdfs'] + 'sameAs'))
        hf.addProperty(graph, exnode, node, rdflib.URIRef(nss['rdfs'] + 'sameAs'))

    return node
Exemplo n.º 2
0
def fuzzyTextMatchElseNew(graph, default_graphs, basens, ctype, attrs=[], string='', lang='nl', max_diff=.4, interactive=True,\
                          align='off', endpoint=''):
    exnode = None
    if align == 'local' or align == 'global' or align == 'both':
        (exnode, source) = fuzzyTextMatch(graph, default_graphs, ctype, attrs,
                                          string, max_diff, interactive, align,
                                          endpoint)

    # guarantee uniqueness within a converted graph
    if source == graph:
        return exnode

    # else ensure complete graph by using 'sameAs'
    nss = dict(ns for ns in graph.namespace_manager.namespaces())
    hid = hf.genHash(None, None, [], salt=string + ctype.toPython())
    node = hf.getNode(graph, hid)
    if node is None:
        node = rdflib.URIRef(basens + hid)
        hf.addType(graph, node, ctype)
        label = rdflib.Literal(string,
                               datatype=rdflib.URIRef(nss['xsd'] + 'string'))
        hf.addLabel(graph, node, label, lang)

    if exnode is not None and exnode.toPython() != node.toPython():
        hf.addProperty(graph, node, exnode,
                       rdflib.URIRef(nss['rdfs'] + 'sameAs'))
        hf.addProperty(graph, exnode, node,
                       rdflib.URIRef(nss['rdfs'] + 'sameAs'))

    return node
Exemplo n.º 3
0
    def propertyHandler(self, element, basename, superprop, proprange=None):
        node = rdflib.URIRef(self.basens + self.baseid + '_' + element.attrib['name'])
        hf.addType(self.graph, node, rdflib.URIRef(self.nss['rdf'] + 'Property'))
        hf.addProperty(self.graph, node, superprop, rdflib.URIRef(self.nss['rdfs'] + 'subpropertyOf'))
        hf.addLabel(self.graph, node, element.attrib['name'] + ' van ' + basename, 'nl')
        #self.addDoc(element, node)

        hf.addProperty(self.graph, node, rdflib.URIRef(self.basens + self.baseid + '_' + basename.title()), rdflib.URIRef(self.nss['rdfs'] + 'domain'))
        if proprange is not None:
            hf.addProperty(self.graph, node, proprange, rdflib.URIRef(self.nss['rdfs'] + 'range'))
Exemplo n.º 4
0
 def classHandler(self, ctype, name, superclass):
     node = rdflib.URIRef(self.basens + self.baseid + '_' + name)
     hf.addType(self.graph, node, rdflib.URIRef(self.nss['rdf'] + 'Resource'))
     hf.addSubClassOf(self.graph, node, superclass)
     hf.addLabel(self.graph, node, name, 'nl')
     self.addDoc(ctype, node)