当前位置: 首页>>代码示例>>Python>>正文


Python ConjunctiveGraph.load方法代码示例

本文整理汇总了Python中rdflib.ConjunctiveGraph.load方法的典型用法代码示例。如果您正苦于以下问题:Python ConjunctiveGraph.load方法的具体用法?Python ConjunctiveGraph.load怎么用?Python ConjunctiveGraph.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdflib.ConjunctiveGraph的用法示例。


在下文中一共展示了ConjunctiveGraph.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
    def __init__(self, path=None):
        self.__dict__ = self.__shared_state
        if (self.data == None):
            if (path == None):
                raise ValueError("djubby's configuration MUST be initialized a first time, read http://code.google.com/p/djubby/wiki/GettingStarted")
            else:
                self.path = os.path.abspath(path)
                logging.debug("Reading djubby's configuration from %s..." % self.path)
                if (not os.path.exists(self.path)):
                    raise ValueError("Not found a proper file at '%s' with a configuration for djubby. Please, provide a right path" % self.path)

                data = ConjunctiveGraph()
                data.bind("conf", ns.config) 
                try:
                    data.load(path, format='n3') 
                except Exception, e:
                    raise ValueError("Not found a proper N3 file at '%s' with a configuration for djubby. Please, provide a valid N3 file" % self.path)

                self.data = data
                try:
                    self.graph = self.get_value("sparqlDefaultGraph")
                    self.endpoint = self.get_value("sparqlEndpoint")
                except Exception, e:
                    raise ValueError("Not found the graph not the endpoint that it's supposed djubby have to query. Please, provide a right donfiguration")

                logging.info("Using <%s> as default graph to query the endpoint <%s>" % (self.graph, self.endpoint))
                self.__class__.__dict__['_Configuration__shared_state']["data"] = data #FIXME
开发者ID:mpetyx,项目名称:djubby,代码行数:29,代码来源:configuration.py

示例2: get_all_measurement_types

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
def get_all_measurement_types(ontology_file):
    graph = ConjunctiveGraph()
    graph.load(ontology_file, format="n3")
    query_str = '''SELECT DISTINCT ?mt ?label ?comment ?defn
        WHERE {
          ?mt rdfs:label ?label .
          ?mt rdfs:subClassOf <%s> .
          ?mt rdfs:subClassOf ?r1 .
          ?r1 owl:onProperty oboe:measuresEntity ; owl:someValuesFrom ?ent .
          ?mt rdfs:subClassOf ?r2 .
          ?r2 owl:onProperty oboe:measuresCharacteristic ; owl:someValuesFrom ?char .
          OPTIONAL { ?mt rdfs:comment ?comment }
          OPTIONAL { ?mt skos:definition ?defn }
        }''' % (MeasurementType)
    qres = list(graph.query(query_str, initNs=dict(oboe=URIRef("http://ecoinformatics.org/oboe/oboe.1.2/oboe-core.owl#"),
                                                   owl=OWL,rdfs=RDFS,skos=SKOS)))
    if len(qres) > 0:
        qres.sort(key=lambda x: x[0], reverse=True)
        result = dict()
        i = 0
        for row in qres:
            result[i] = {'uri' : row[0], 'label' : row[1], 'comment' : row[2], 'defn' : row[3]}
            i = i + 1
        print "Sparql query finished!"
        return result
    return None
开发者ID:tetherless-world,项目名称:linkipedia,代码行数:28,代码来源:AutoAnnotate_CNN_Character_Similarity.py

示例3: update

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
def update():
    """
    Update the library with new articles.
    """
    graph = ConjunctiveGraph()
    # load the existing graph
    library = 'data/articles.rdf'
    graph.load(library)

    feeds = {
        "http://www3.interscience.wiley.com/rss/journal/118485807": "wiley.xsl",
        "http://phg.sagepub.com/rss/current.xml": "sage.xsl",
        "http://www.informaworld.com/ampp/rss~content=t713446924": "infoworld.xsl",
        "http://www.informaworld.com/ampp/rss~content=t788352614": "infoworld.xsl",
        "http://www.envplan.com/rss.cgi?journal=D": "envplan.xsl",
        "http://www.envplan.com/rss.cgi?journal=A": "envplan.xsl",
        "http://cgj.sagepub.com/rss/current.xml": "sage.xsl"
        }

    for feed, stylesheet in feeds.iteritems():
        # grab the feed and transform it
        print "grabbing ", feed
        new = StringIO.StringIO(feed_transform(feed, stylesheet))
        # merge the new triples into the graph
        graph.parse(new)
        new.close()

    graph.serialize(library, format='pretty-xml')
开发者ID:bdarcus,项目名称:LitFeed,代码行数:30,代码来源:litfeed.py

示例4: RecursionTests

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
class RecursionTests(unittest.TestCase):
    # debug = True
    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.load(StringIO(testContent), format='n3')

    def test_simple_recursion(self):
        graph = ConjunctiveGraph()
        graph.load(StringIO(BASIC_KNOWS_DATA), format='n3')
        results = graph.query(KNOWS_QUERY,
                              processor="sparql", 
                              DEBUG=False)
        results = set(results)
        person1 = URIRef('ex:person.1')
        person2 = URIRef('ex:person.2')
        nose.tools.assert_equal(
          results,
          set([(person1, None), (person1, Literal('person 3')),
               (person2, Literal('person 3'))]))

    def test_secondary_recursion(self):
        graph = ConjunctiveGraph()
        graph.load(StringIO(SUBCLASS_DATA), format='n3')
        results = graph.query(SUBCLASS_QUERY,
                              processor="sparql", 
                              DEBUG=False)
        results = set(results)
        ob = URIRef('ex:ob')
        class1 = URIRef('ex:class.1')
        class2 = URIRef('ex:class.2')
        class3 = URIRef('ex:class.3')
        nose.tools.assert_equal(
          results,
          set([(ob, class1), (ob, class2), (ob, class3)]))
开发者ID:RDFLib,项目名称:rdfextras,代码行数:36,代码来源:test_sparql_recurse.py

示例5: catalyst_graph_for

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
def catalyst_graph_for(file):
    if file.startswith("/"):
        file = "file://" + file
    logging.info("InferenceStore catalyst_graph_for started")

    # quads = jsonld.to_rdf(file, {'format': 'application/nquads'})
    logging.info("InferenceStore JSON-LD loaded")

    g = ConjunctiveGraph()
    g.namespace_manager = namespace_manager
    # g.parse(data=quads, format='nquads')
    g.load(file, format="json-ld")
    logging.info("InferenceStore base graph loaded")

    f = FuXiInferenceStore.get_instance()

    # get the inference engine
    cl = f.get_inference(g)
    logging.info("InferenceStore inference graph loaded")

    union_g = rdflib.ConjunctiveGraph()

    for s, p, o in g.triples((None, None, None)):
        union_g.add((s, p, o))

    for s, p, o in cl.triples((None, None, None)):
        union_g.add((s, p, o))

    logging.info("InferenceStore union graph prepared")

    return union_g
开发者ID:mapofemergence,项目名称:edgesense,代码行数:33,代码来源:inference.py

示例6: to_rdf_etree

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
def to_rdf_etree(sources):
    graph = ConjunctiveGraph()
    for source in sources:
        graph.load(source, format=guess_format(source))
    io = StringIO()
    graph.serialize(io, format="pretty-xml")
    io.seek(0)
    return etree.parse(io)
开发者ID:niklasl,项目名称:oort,代码行数:10,代码来源:run_rdfa_template.py

示例7: build_network

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
def build_network(rules):
    if isinstance(rules, basestring):
        rules = StringIO(rules)
    graph = ConjunctiveGraph()
    graph.load(rules, publicID='test', format='n3')
    network = NetworkFromN3(graph,
                            additionalBuiltins={STRING_NS.startsWith:StringStartsWith})
    network.feedFactsToAdd(generateTokenSet(extractBaseFacts(graph)))
    return network
开发者ID:Bazmundi,项目名称:fuxi,代码行数:11,代码来源:test_builtin_ordering.py

示例8: build_network2

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
def build_network2(rules):
    graph = ConjunctiveGraph()
    graph.load(StringIO(rules), publicID='test', format='n3')    
    rule_store, rule_graph=SetupRuleStore(
                      StringIO(rules),
                      additionalBuiltins={STRING_NS.startsWith:StringStartsWith})
    from FuXi.Rete.Network import ReteNetwork
    network = ReteNetwork(rule_store)
    network.feedFactsToAdd(generateTokenSet(extractBaseFacts(graph)))
    return network
开发者ID:Bazmundi,项目名称:fuxi,代码行数:12,代码来源:test_builtin_ordering.py

示例9: labchords2RDF

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
def labchords2RDF(infilename, outfilename, format="xml", audiofilename=None, withdescriptions=False):
	if withdescriptions:
		commonchords = ConjunctiveGraph()
		commonchords.load("CommonChords.rdf")
		extrachords = ConjunctiveGraph()
	
	infile = open(infilename, 'r')
	lines = infile.readlines()

	mi = mopy.MusicInfo()

	homepage = mopy.foaf.Document("http://sourceforge.net/projects/motools")
	mi.add(homepage)
	program = mopy.foaf.Agent()
	program.name = "labchords2RDF.py"
	program.homepage = homepage
	mi.add(program)

	
	tl = RelativeTimeLine("#tl")
	tl.label = "Timeline derived from "+infilename
	tl.maker = program
	mi.add(tl)
	
	intervalNum = 0
	for line in lines:
		i = Interval("#i"+str(intervalNum))
		try:
			[start_s, end_s, label] = parseLabLine(line)
			i.beginsAtDuration = secondsToXSDDuration(start_s)
			i.endsAtDuration = secondsToXSDDuration(end_s)
			#i.label = "Interval containing "+label+" chord."
			i.onTimeLine = tl
			
			# Produce chord object for the label :
			chordURI = "http://purl.org/ontology/chord/symbol/"+label.replace("#","s").replace(",","%2C")

			if withdescriptions and \
			   len(list(commonchords.predicate_objects(URIRef(chordURI)))) == 0 and \
			   len(list(extrachords.predicate_objects(URIRef(chordURI)))) == 0:
				# Deref to grab chord info
				print "loading "+chordURI+"..."
				extrachords.load(chordURI)
				
			c = mopy.chord.Chord(chordURI)
			c_event = mopy.chord.ChordEvent("#ce"+str(intervalNum))
			c_event.chord = c
			c_event.label = label
			c_event.time = i
		except Exception, e:
			raise Exception("Problem parsing input file at line "+str(intervalNum+1)+" !\n"+str(e))
		mi.add(i)
		mi.add(c)
		mi.add(c_event)
		intervalNum+=1
开发者ID:apassant,项目名称:motools,代码行数:57,代码来源:labchords2RDF.py

示例10: TestSparqlOPT_FILTER2

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
class TestSparqlOPT_FILTER2(unittest.TestCase):
    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.load(StringIO(testContent), format='n3')
    def test_OPT_FILTER(self):
        results = self.graph.query(QUERY,
                                   DEBUG=False)
        results = list(results)
        self.failUnless(
            results == [(doc1,)],
            "expecting : %s .  Got: %s"%([(doc1,)],repr(results)))
开发者ID:pombredanne,项目名称:rdfextras,代码行数:13,代码来源:test_sparql_naf2.py

示例11: Install

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
class Install(RDFFile):
    """
    TODO: Add documentation
    """

    def __init__(self, fileName):
        self.graph = ConjunctiveGraph()
        self.subject = URIRef("urn:mozilla:install-manifest")
        try:
            self.graph.load(fileName)
        except IOError, e:
            pass
开发者ID:mattprintz,项目名称:xpibuilder,代码行数:14,代码来源:Install.py

示例12: main

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
def main(filename, name):
    all_sections = getCharSheetSections()

    charactersheet = NS('http://trinket.thorne.id.au/2007/%s.n3#' % name)
    character = URIRef(charactersheet + name)

    graph = ConjunctiveGraph()
    for f in glob.glob(os.path.join(sibpath(__file__, 'data'), '*.n3')):
        if f.endswith('monster.n3'):
            continue
        try: graph.load(f, format='n3')
        except Exception, e:
            print 'Could not load', f, 'because', e
开发者ID:corydodt,项目名称:Playtools,代码行数:15,代码来源:charsheet.py

示例13: _convertRDF

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
 def _convertRDF(self) :
     """
     Convert an RDF/XML result into an RDFLib triple store. This method can be overwritten
     in a subclass for a different conversion method.
     @return: converted result
     @rtype: RDFLib Graph
     """
     from rdflib import ConjunctiveGraph
     retval = ConjunctiveGraph()
     # this is a strange hack. If the publicID is not set, rdflib (or the underlying xml parser) makes a funny
     #(and, as far as I could see, meaningless) error message...
     retval.load(self.response,publicID=' ')
     return retval
开发者ID:KiranAjayakumar,项目名称:python-dlp,代码行数:15,代码来源:Wrapper.py

示例14: test_simple_recursion

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
 def test_simple_recursion(self):
     graph = ConjunctiveGraph()
     graph.load(StringIO(BASIC_KNOWS_DATA), format='n3')
     results = graph.query(KNOWS_QUERY,
                           processor="sparql", 
                           DEBUG=False)
     results = set(results)
     person1 = URIRef('ex:person.1')
     person2 = URIRef('ex:person.2')
     nose.tools.assert_equal(
       results,
       set([(person1, None), (person1, Literal('person 3')),
            (person2, Literal('person 3'))]))
开发者ID:RDFLib,项目名称:rdfextras,代码行数:15,代码来源:test_sparql_recurse.py

示例15: test_secondary_recursion

# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import load [as 别名]
 def test_secondary_recursion(self):
     graph = ConjunctiveGraph()
     graph.load(StringIO(SUBCLASS_DATA), format='n3')
     results = graph.query(SUBCLASS_QUERY,
                           processor="sparql", 
                           DEBUG=False)
     results = set(results)
     ob = URIRef('ex:ob')
     class1 = URIRef('ex:class.1')
     class2 = URIRef('ex:class.2')
     class3 = URIRef('ex:class.3')
     nose.tools.assert_equal(
       results,
       set([(ob, class1), (ob, class2), (ob, class3)]))
开发者ID:RDFLib,项目名称:rdfextras,代码行数:16,代码来源:test_sparql_recurse.py


注:本文中的rdflib.ConjunctiveGraph.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。