def _time_interval(self, subject, predicate):
'''
Returns the start and end date for a time interval object
Both subject and predicate must be rdflib URIRef or BNode objects
It checks for time intervals defined with both schema.org startDate &
endDate and W3C Time hasBeginning & hasEnd.
Note that partial dates will be expanded to the first month / day
value, eg '1904' -> '1904-01-01'.
Returns a tuple with the start and end date values, both of which
can be None if not found
'''
start_date = end_date = None
for interval in self.g.objects(subject, predicate):
# Fist try the schema.org way
start_date = self._object_value(interval, SCHEMA.startDate)
end_date = self._object_value(interval, SCHEMA.endDate)
if start_date or end_date:
return start_date, end_date
# If no luck, try the w3 time way
start_nodes = [t for t in self.g.objects(interval,
TIME.hasBeginning)]
end_nodes = [t for t in self.g.objects(interval,
TIME.hasEnd)]
if start_nodes:
start_date = self._object_value(start_nodes[0],
TIME.inXSDDateTime)
if end_nodes:
end_date = self._object_value(end_nodes[0],
TIME.inXSDDateTime)
return start_date, end_date
评论列表
文章目录