/
Subject_planet.py
44 lines (37 loc) · 1.36 KB
/
Subject_planet.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
# ###################################################
# 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
def find_planet_subjects(first_key):
query_str = """
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX dcterms: <http://purl.org/dc/terms/>
select distinct ?super
where
{
dbpedia:""" + first_key + """ dcterms:subject ?super
}"""
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;