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


Python URIRef.replace方法代码示例

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


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

示例1: enterNewAnnotationMenu

# 需要导入模块: from rdflib import URIRef [as 别名]
# 或者: from rdflib.URIRef import replace [as 别名]
    def enterNewAnnotationMenu(self):
        '''
        Interactive input for a new annotation
        '''
        
        self.printNewAnnotationMenu()

        i = 1
        for year in self.yearsAnnotations:
          print '{}) {}'.format(i,year["year"])
          i += 1
        print
            
        year = raw_input('Table to annotate: ')
        cell = raw_input('Cell to annotate: ')
        author = raw_input('Author: ')
        corrected = raw_input('Corrected value (leave blank if none): ')
        flag = raw_input('Flag: ')

        graphURI = URIRef(self.yearsAnnotations[int(year)-1]["uri"])
        d2sGraphURI = graphURI.replace("cedar-project.nl", "www.data2semantics.org")
        annoURI = URIRef(d2sGraphURI + '/NOORDBRABANT/' + cell)
        cellURI = annoURI.replace("annotations", "data")

        # Create the new annotation
        query = """
            PREFIX oa: <http://www.w3.org/ns/openannotation/core/>
            PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

            INSERT INTO GRAPH <""" + graphURI  + """>
            {
                <""" + annoURI  + """> a oa:Annotation;
                oa:annotated \"""" + str(datetime.datetime.now().strftime("%Y-%m-%d")) + """\"^^xsd:date;
                oa:annotator \"""" + author  + """\";
                oa:generated \"""" + str(datetime.datetime.now().strftime("%Y-%m-%d")) + """\"^^xsd:date;
                oa:generator <https://cedar-project.nl/tools/cedar-demo.py>;
                oa:hasBody [ rdf:value \"""" + corrected + ' ' + flag  + """\" ];
                oa:hasTarget <""" + cellURI  + """>;
                oa:modelVersion <http://www.openannotation.org/spec/core/20120509.html> .
            }
        """

        # query = "INSERT INTO GRAPH <http://cedar-project.nl/annotations/VT_1859_01_H1> {<http://a> rdf:type <http:b>}"

        print query

        self.sparql.setQuery(query)

        self.sparql.setReturnFormat(JSON)
        self.results = self.sparql.query().convert()
开发者ID:CEDAR-project,项目名称:MP2Demo,代码行数:52,代码来源:MP2Demo.py

示例2: get_service

# 需要导入模块: from rdflib import URIRef [as 别名]
# 或者: from rdflib.URIRef import replace [as 别名]
def get_service():
    g = new_graph()
    me = URIRef(url_for('get_service', _external=True))
    g.add((me, RDF.type, SERVICE_TYPE))
    for db_resource in service_graph.subjects(RDF.type, PARTITION.Root):
        db_resource = URIRef(
            url_for('get_resource', rid=db_resource.replace(URI_PREFIX, ""), _external=True))
        g.add((me, CONTAINMENT_LINK, db_resource))
    response = make_response(g.serialize(format='turtle'))
    response.headers['Content-Type'] = 'text/turtle'
    return response
开发者ID:fserena,项目名称:rdf2rest,代码行数:13,代码来源:api.py

示例3: relativize

# 需要导入模块: from rdflib import URIRef [as 别名]
# 或者: from rdflib.URIRef import replace [as 别名]
 def relativize(self, uri):
     base = URIRef(self.base)
     basedir = URIRef(self.base if base.endswith('/') else base.rsplit('/', 1)[0])
     if base is not None:
         if uri == base:
             uri = URIRef('')
         elif uri == basedir:
             uri = URIRef('.')
         elif uri.startswith(basedir + '/'):
             uri = URIRef(uri.replace(basedir + '/', "", 1))
     return uri
开发者ID:bodleian,项目名称:datafinder,代码行数:13,代码来源:serializers.py

示例4: _formatNodeURIRef

# 需要导入模块: from rdflib import URIRef [as 别名]
# 或者: from rdflib.URIRef import replace [as 别名]
def _formatNodeURIRef(uriref, anno_uri, body_uri):
    '''
        Rewrite a URIRef according to the node configuration
        * uriref:rdflib.URIRef 
        * anno_uri:String as hexadecimal 
        * body_uri:String as hexadecimal
    ''' 
    if isinstance(uriref, URIRef) and NODE_URI in uriref:
        uriref = URIRef(uriref.replace(NODE_URI,
                               getattr(settings,
                                       'NODE_URI', 
                                       NODE_URI) + '/'))

    if isinstance(uriref, URIRef) and CH_NODE in uriref:
        uriref = URIRef(uriref.replace(CH_NODE + ':', 
                                       getattr(settings, 'NODE_URI', NODE_URI) + '/'))        
    if isinstance(uriref, URIRef) and ANNO_URI in uriref:
        uriref = URIRef(uriref.replace(ANNO_URI, "resource/" + anno_uri))
    if isinstance(uriref, URIRef) and BODY_URI in uriref:
        uriref = URIRef(uriref.replace(BODY_URI, "resource/" + body_uri))    
    return uriref
开发者ID:CHARMe-Project,项目名称:djcharme,代码行数:23,代码来源:actions.py

示例5: _update_namespace

# 需要导入模块: from rdflib import URIRef [as 别名]
# 或者: from rdflib.URIRef import replace [as 别名]
    def _update_namespace(self):
        # updating the namespace
        OLD = "file://" + os.path.join(
                os.path.dirname(__file__), 'data', WIT_FILENAME)
        NEW = "http://www.w3.org/2005/Incubator/webid/earl/%s#" % WIT

        for cid, _, source in self.g.triples((None, None, None)):
            if source:
                try:
                    context = self.g.get_context(cid)
                    for s, p, o in context:
                        context.remove((s, p, o))
                        if isinstance(s, URIRef) and OLD in s:
                            s = URIRef(s.replace(OLD, NEW))
                        if isinstance(s, rdflib.URIRef) and OLD in p:
                            p = URIRef(p.replace(OLD, NEW))
                        if isinstance(o, URIRef) and OLD in o:
                            o = URIRef(o.replace(OLD, NEW))
                        context.add((s, p, o))
                except Exception, e:
                    #print e
                    raise e
开发者ID:bennomadic,项目名称:python-webid,代码行数:24,代码来源:earl.py

示例6: tableView_objectValueForTableColumn_row_

# 需要导入模块: from rdflib import URIRef [as 别名]
# 或者: from rdflib.URIRef import replace [as 别名]
    def tableView_objectValueForTableColumn_row_(self, tableView, tableColumn, row):
	id = tableColumn.identifier()
	uri = self.resources[row]
	if id=="uri":
	    base =self.context
	    base = base.split("#", 1)[0]
            uri = URIRef(uri.replace(base, "", 1)) # relativize
	    return uri
	elif id=="label":
	    return self.redfoot.label(uri, "")
	elif id=="comment":
	    return self.redfoot.comment(uri, "")
	else:
	    return ""
开发者ID:eikeon,项目名称:redfoot,代码行数:16,代码来源:EditorController.py

示例7: convert

# 需要导入模块: from rdflib import URIRef [as 别名]
# 或者: from rdflib.URIRef import replace [as 别名]
def convert(teifile, namespace):
	#graph_uri = "http://contextus.net/resource/blue_velvet/"
	
	ns = Namespace(namespace)

	graph = ConjunctiveGraph()
	graph.load(teifile, format="rdfa")
	
	graph.bind("default", ns)
	
	to_update = ""

	for prefix, nsuri in graph.namespaces(): 
		#print("prefix: " + str(prefix) + " - " + str(nsuri))
		if nsuri in ns:
			to_update = nsuri
			
	for s, p, o in graph:
#    		print s, p, o
    		if to_update != "" and to_update in s:
    			graph.remove((s, p, o))
			s = URIRef(s.replace(to_update, ns))			
			graph.add((s, p, o))
	
	act = ""
	scene = ""
	line = ""
	char = 0
	loc = 0
	
	
	#timeline = ns['timeline/narrative']
	#graph.add((timeline, RDF.type, ome['Timeline']))

	tree = ET.parse(teifile)
	cast = dict()
	
	titleNode = tree.find('//title')
	
	castItems = tree.findall('/text/body/div1/castList//castItem')
	for castItem in castItems:
		actorNode = castItem.find('actor')
		roleNode = castItem.find('role')

		if roleNode != None:
			id = roleNode.get("{http://www.w3.org/XML/1998/namespace}id")
		
		#print("Found castItem!")

		actor = None
		role = None

		# Check to see if we already have an entry
		if(roleNode != None and roleNode.get("about")):		

			charname = roleNode.get("about")
			
			if(charname.find(":") > -1):
				nmsp,nom = charname.split(":", 1)		
				charcode =  "character/" + str(char)
				charref = nmsp + ":" + charcode + "]"
				role = extractCURIEorURI(graph, charref,nom[0:-1])
				char += 1		
				#print("1:" + charname + ": adding id " + id + " to " + role)
			else:
				role = extractCURIEorURI(graph, charname)
				#print("2:" + charname + ": adding id " + id + " to " + role)

			cast[id] = role
			graph.add((role, RDF.type, omb['Character']))
			#print(charname + ": adding id " + id + " to " + role)
		
		if(actorNode != None and actorNode.get("about")):
			actor = extractCURIEorURI(graph, actorNode.get("about"))
			graph.add((actor, RDF.type, omb['Being']))

		if actor != None and role != None:
			graph.add((actor, omb['portrays'], role))
			graph.add((role, omb['portrayed-by'], actor))

	eventCount = 1
	groupCount = 1
	prior_event = None
	
	actItems = tree.findall('/text/body/div1')
	ref = ""
	
	for actItem in actItems:
	
		if actItem.get("type") == "act":
			act = actItem.get("n")
		
		sceneItems = actItem.findall('div2')
		
		for sceneItem in sceneItems:
			
			#print("Found sceneItems!")
			
			if sceneItem.get("type") == "scene":
				scene = sceneItem.get("n")		
#.........这里部分代码省略.........
开发者ID:klaffenboeck,项目名称:contextus,代码行数:103,代码来源:tei2onto2.py

示例8: relativize

# 需要导入模块: from rdflib import URIRef [as 别名]
# 或者: from rdflib.URIRef import replace [as 别名]
 def relativize(self, uri):
     base = self.base
     if base is not None and uri.startswith(base):
         uri = URIRef(uri.replace(base, "", 1))
     return uri
开发者ID:Ju2ender,项目名称:watchdog,代码行数:7,代码来源:__init__.py


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