def show(self, id, format="html"): """GET /vocabulary/search/id: Show a specific item""" # url('vocabulary_search', id=ID) import re id = re.sub("http:/", "http://", id) query = """ SELECT DISTINCT rdfdoc.id, rdfdoc.uri FROM rdfdoc, stat_result, rdf_property_stat, rdf_property WHERE rdf_property.uri='%s' AND rdf_property.id=rdf_property_stat.rdf_property_id AND rdf_property_stat.stat_result_id=stat_result.id AND stat_result.rdfdoc_id=rdfdoc.id ORDER BY rdfdoc.id; """ % ( id ) try: datasets = [] result = Session.execute(query) for row in result: obj = {"id": row[0], "uri": row[1]} datasets.append(obj) return json.dumps(datasets) except: return json.dumps("")
def _rankSuggestionLodstats(self, suggestionUri, entities): #The most time consuming - implement caching here #just cache to /tmp for now onlyclasses = set() for entity in entities: onlyclasses.add(entity['class']) onlyclasses = list(onlyclasses) cacheId = uuid.uuid5(uuid.NAMESPACE_URL, suggestionUri.join(sorted(onlyclasses)).encode('utf-8')) cachePath = '/tmp/' cacheNamespace = 'suggestionsCache' cacheEntry = str(cachePath) + str(cacheNamespace) + str(cacheId) if(os.path.exists(cacheEntry)): return pickle.load(open(cacheEntry, 'rb')) propertyQuery = """SELECT stat_result_id FROM rdf_property_stat, rdf_property WHERE rdf_property.id=rdf_property_stat.rdf_property_id AND rdf_property.uri='%s';""" % suggestionUri q = Session.execute(propertyQuery) propertyDatasets = set() for row in q: propertyDatasets.add(row[0]) entitiesDatasets = set() for entityUrl in onlyclasses: classQuery = """SELECT stat_result_id FROM rdf_class_stat_result, rdf_class WHERE rdf_class_stat_result.rdf_class_id=rdf_class.id AND rdf_class.uri='%s';""" % entityUrl q = Session.execute(classQuery) for row in q: entitiesDatasets.add(row[0]) propertyQuery = """SELECT stat_result_id FROM rdf_property_stat, rdf_property WHERE rdf_property.id=rdf_property_stat.rdf_property_id AND rdf_property.uri='%s';""" % entityUrl q = Session.execute(propertyQuery) for row in q: entitiesDatasets.add(row[0]) common = propertyDatasets.intersection(entitiesDatasets) pickle.dump(len(common), open(cacheEntry, 'wb'), protocol=pickle.HIGHEST_PROTOCOL) return len(common)