/
find_ontologyClass.py
49 lines (43 loc) · 1.67 KB
/
find_ontologyClass.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
44
45
46
47
# ###################################################
# 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
def find_planet_property(first_key):
query_str = """
PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX category: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select distinct ?super
where
{
dbpedia:""" + first_key + """ rdf:type ?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;