Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
First step for itemprop-reverse: slight reorganization of the triple …
Browse files Browse the repository at this point in the history
…generation part
  • Loading branch information
iherman committed Dec 5, 2014
1 parent 29097ac commit 214f30d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pyMicrodata/microdata.py
Expand Up @@ -361,22 +361,26 @@ def generate_triples(self, item, context) :
# todo: what follows has to be duplicated with the get_item_inverse_properties and the corresponding changes
# but... what if the target/object is a literal? That must be filtered out...

def get_predicate_object(prop, name) :
# 9.1.1. set a new context
new_context = context.new_copy(itype)
# 9.1.2, generate the URI for the property name, that will be the predicate
# Also update the context
# Note that the method also checks, and stores, the possible superproperty/equivalent property values
new_context.current_name = predicate = self.generate_predicate_URI(name, new_context)
# 9.1.3, generate the property value. The extra flag signals that the value is a new item
# Note that 9.1.4 step is done in the method itself, ie, a recursion may occur there
# if a new item is hit (in which case the return value is a RDF resource chaining to a subject)
# Note that the value may be None (e.g, for an <img> element without a @src), in which case nothing
# is generated
value = self.get_property_value(prop, new_context)
return (predicate, value)

# Step 9: Get the item properties and run a cycle on those
# each entry in the dictionary is an array of RDF objects
for prop in self.get_item_properties(item) :
for name in prop.getAttribute("itemprop").strip().split() :
# 9.1.1. set a new context
new_context = context.new_copy(itype)
# 9.1.2, generate the URI for the property name, that will be the predicate
# Also update the context
# Note that the method also checks, and stores, the possible superproperty/equivalent property values
new_context.current_name = predicate = self.generate_predicate_URI(name, new_context)
# 9.1.3, generate the property value. The extra flag signals that the value is a new item
# Note that 9.1.4 step is done in the method itself, ie, a recursion may occur there
# if a new item is hit (in which case the return value is a RDF resource chaining to a subject)
# Note that the value may be None (e.g, for an <img> element without a @src), in which case nothing
# is generated
value = self.get_property_value(prop, new_context)
(predicate, value) = get_predicate_object(prop, name)
if value is None : continue
# 9.1.5, generate the triple
self.graph.add((subject, URIRef(predicate), value))
Expand Down

0 comments on commit 214f30d

Please sign in to comment.