Example #1
0
	def convert( self ) :
		"""
		Top level entry to convert and generate all the triples. It finds the top level items,
		and generates triples for each of them; additionally, it generates a top level entry point
		to the items from base in the form of an RDF list.
		"""
		item_list = []
		for top_level_item in self.get_top_level_items() :
			item_list.append( self.generate_triples(top_level_item, Evaluation_Context()) )
		list = generate_RDF_collection( self.graph, item_list )
		self.graph.add( (URIRef(self.base),self.ns_md["item"],list) )
Example #2
0
	def generate_property_values( self, subject, predicate, objects, context) :
		"""
		Generate the property values for for a specific subject and predicate. The context should specify whether
		the objects should be added in an RDF list or each triples individually.
		
		@param subject: RDF subject
		@type subject: RDFLib Node (URIRef or blank node)
		@param predicate: RDF predicate
		@type predicate: RDFLib URIRef
		@param objects: RDF objects
		@type objects: list of RDFLib nodes (URIRefs, Blank Nodes, or literals)
		@param context: evaluation context
		@type context: L{Evaluation_Context}
		"""
		# generate triples with a list, or a bunch of triples, depending on the context
		# The biggest complication is to find the method...
		method = ValueMethod.unordered
		superproperties = None
		
		# This is necessary because predicate is a URIRef, and I am not sure the comparisons would work well
		# to be tested, in fact...
		pred_key = "%s" % predicate
		for key in registry :
			if predicate.startswith(key) :
				# This the part of the registry corresponding to the predicate's vocabulary
				registry_object = registry[key]
				try :
					if "multipleValues" in registry_object : method = registry_object["multipleValues"]
					# The generic definition can be overwritten for a specific property. The simplest is to rely on a 'try'
					# with the right structure...
					try :
						method = registry_object["properties"][pred_key[len(key):]]["multipleValues"]
					except :
						pass
				except :
					pass
		
		if method == ValueMethod.unordered :
			for object in objects :
				self.graph.add( (subject, predicate, object) )
		else :
			self.graph.add( (subject,predicate,generate_RDF_collection( self.graph, objects )) )
Example #3
0
	def convert( self ) :
		"""
		Top level entry to convert and generate all the triples. It finds the top level items,
		and generates triples for each of them; additionally, it generates a top level entry point
		to the items from base in the form of an RDF list.
		"""
		item_list = []
		for top_level_item in self.get_top_level_items() :
			item_list.append( self.generate_triples(top_level_item, Evaluation_Context()) )
		list = generate_RDF_collection( self.graph, item_list )
		self.graph.add( (URIRef(self.base),self.ns_md["item"],list) )
		
		# If the vocab expansion is also switched on, this is the time to do it.
		# I have put this into a try:... except:, because there is a dependency on the pyRdfa package. If that
		# is not available, the rest of the processing should go on...
		# if self.vocab_expansion and vocabularies_used > 0 :
		# 	try :
		# 		from pyRdfa.rdfs.process import MiniOWL
		# 		MiniOWL(self.graph).closure()
		# 	except :
		# 		pass

		# This is the version with my current proposal: the basic expansion is always there;
		# the follow-your-nose inclusion of vocabulary is optional
		if self.vocabularies_used :
			try :
				from pyRdfa.rdfs.process import MiniOWL, process_rdfa_sem
				from pyRdfa.options import Options
				# if we did not get here, the pyRdfa package could not be
				# imported. Too bad, but life should go on in the except branch...
				if self.vocab_expansion :
					# This is the full deal
					options = Options(vocab_expansion = self.vocab_expansion, vocab_cache = self.vocab_cache)
					process_rdfa_sem(self.graph, options)
				else :
					MiniOWL(self.graph).closure()
			except :
				pass