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


Python NamespaceManager.normalizeUri方法代码示例

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


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

示例1: Sketch

# 需要导入模块: from rdflib.namespace import NamespaceManager [as 别名]
# 或者: from rdflib.namespace.NamespaceManager import normalizeUri [as 别名]

#.........这里部分代码省略.........
		for pref in PREFIXES:
			self.bind(pref)
		if text:
			self.add(text)
		
	def add(self, text="", default_continuousAdd=True):
		"""add some turtle text"""
		if not text and default_continuousAdd:
			self.continuousAdd()
		else:
			pprefix = ""
			for x,y in self.rdfGraph.namespaces():
				pprefix += "@prefix %s: <%s> . \n" % (x, y)
			# add final . if missing
			if text and (not text.strip().endswith(".")):
				text += " ."
			# smart replacements
			text = text.replace(" sub ", " rdfs:subClassOf ")
			text = text.replace(" class ", " owl:Class ")
			# finally
			self.rdfGraph.parse(data=pprefix+text, format="turtle")
	
	
	# note: problem here if typying ### on first line! 
	def continuousAdd(self):
		print "Multi-line input. Enter ### when finished."
		temp = ""
		sentinel = "###"
		for line in iter(raw_input, sentinel):
			if line.strip() == sentinel:
				break
			if not line.strip().endswith("."):
				line += " ."	
			temp += "%s" % line
		self.add(temp, False) # default_continuousAdd=False	
	
	def bind(self, prefixTuple):
		p, k = prefixTuple
		self.rdfGraph.bind(p, k)
	
	def clear(self):
		""""
		Clears the graph 
			@todo add ability to remove specific triples
		"""
		self.rdfGraph.remove((None, None, None))


	def serialize(self, aformat="turtle"):
		"""
		Serialize graph using the format required
		"""
		if aformat and aformat not in self.SUPPORTED_FORMATS:
			return "Sorry. Allowed formats are %s" % str(self.SUPPORTED_FORMATS)
		if aformat == "dot":
			return self.__serializedDot()
		else:
			# use stardard rdf serializations
			return self.rdfGraph.serialize(format=aformat)

	def __serializedDot(self):
		"""
		DOT format:
		digraph graphname {
			 a -> b [label=instanceOf];
			 b -> d [label=isA];
		 }	
		"""
		temp = ""
		for x,y,z in self.rdfGraph.triples((None, None, None)):
			temp += """"%s" -> "%s" [label="%s"];\n""" % (self.namespace_manager.normalizeUri(x), self.namespace_manager.normalizeUri(z), self.namespace_manager.normalizeUri(y))
		temp = "digraph graphname {\n%s}" % temp
		return temp


	def omnigraffle(self):
		""" tries to open an export directly in omnigraffle """
		temp = self.serialize("dot")
		
		try:  # try to put in the user/tmp folder 
			from os.path import expanduser
			home = expanduser("~")
			filename = home + "/tmp/turtle_sketch.dot"
			f = open(filename, "w")
		except:
			filename = "turtle_sketch.dot"
			f = open(filename, "w")
		f.write(temp)
		f.close()
		try:
			os.system("open " + filename)
		except:
			os.system("start " + filename)

		
	def show(self, aformat="turtle"):
		print self.serialize(aformat)

	def docs(self):
		print self.__docs__		
开发者ID:easton402,项目名称:OntoSPy,代码行数:104,代码来源:sketch.py


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