def indexing_reindex_item (item): full_url = aacore.utils.full_site_url(item.get_absolute_url()) if hasattr(item, 'get_rdf_as_stream'): # in a way the URL here is the resource.url directly ?! stream = item.get_rdf_as_stream() context = RDF.Node(full_url) RDF_MODEL.context_remove_statements(context=context) RDF_MODEL.add_statements(stream, context=context) else: # # FOR DEBUGGING # resp = utils.direct_get_response(item.get_absolute_url()) # page = resp.content # rdfaparser = RDF.Parser("rdfa") # furl = utils.full_site_url(item.get_absolute_url()) # s = rdfaparser.parse_string_as_stream(page, furl) # print "RDFA:", (len(list(s))), "triples" aacore.utils.parse_localurl_into_model(RDF_MODEL, full_url, format="rdfa", baseuri=full_url, context=full_url)
def index(self): """ Inspects the resource and store the information found in the RDF store. """ request = requests.get(self.url, prefetch=False) # Indexes the content with the appropriate agents (sniffers) for sniffer in sniffers: sniffer = sniffer(request=request, model=self.dummy_model) string = sniffer.sniff() if sniffer.test() else None if string: parser = RDF.Parser(name=sniffer.syntax) parser.parse_string_into_model(self.dummy_model, string.encode("utf-8"), self.url) # Replaces from the RDF model the existing statements with the new ones RDF_MODEL.remove_statements_with_context(RDF.Node(self.url)) RDF_MODEL.add_statements(self.dummy_model.as_stream(), RDF.Node(self.url)) RDF_MODEL.sync()