/
Planet_link.py
45 lines (40 loc) · 1.54 KB
/
Planet_link.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# ###################################################
# Explore the direct inked entities between keywords
# Here direct linked entities states the one edge link
# between the two set of Keywords
# Input : Two keywords
# Output : Set of Linked Edges between the two keywords
# The linked edges are the properties between the
# two keywords.
# @ Author : Rituraj Singh
# rituraj.singh@irisa.fr
# Created Time : 18 July 2018, 17 : 45 (GMT + 2)
# At: INRIA/IRISA, Rennes, France
####################################################
from SPARQLWrapper import SPARQLWrapper, JSON
import numpy as np
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
#print(query_str)
#Q1 : dbpedia:India dcterms:subject ?super
#q2 : dbpedia:New_Delhi rdf:type ?super
#q4 : dbpedia:New_Delhi (owl:sameAs|^owl:sameAs)* ?super
#q3 : dbpedia:Hindi ?super dbpedia:India
#q5: dbpedia: """ +first_keyword + """ ?super dbpedia: """ + Second_keyword + """
def planet_link(planet_one, planet_two):
query_str = """
PREFIX dbpedia: <http://dbpedia.org/resource/>
select distinct ?super
where
{
dbpedia:""" + planet_one + """ ?super dbpedia:""" + planet_two + """
}"""
sparql.setQuery(query_str);
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
# print(results);
my_key = [];
for result in results['results']['bindings']:
# print(result['super']['value'])
my_key.append(result['super']['value'])
my_keywords = np.array(my_key)
return my_keywords;