-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphData_Manager.py
182 lines (140 loc) · 6.5 KB
/
graphData_Manager.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from rdflib import Graph, URIRef, Literal, RDF
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore
from sparql_dataframe import get
import pandas as pd
import json
from ModelClasses import QueryProcessor
from auxiliary import readCSV, readJSON
# Establishing class object URIs
JournalArticle = URIRef("https://schema.org/ScholarlyArticle")
BookChapter = URIRef("https://schema.org/Chapter")
ProceedingsPaper = URIRef("http://purl.org/spar/fabio/ProceedingsPaper")
Journal = URIRef("https://schema.org/Periodical")
Book = URIRef("https://schema.org/Book")
Proceedings = URIRef("https://schema.org/EventSeries")
publicationVenue = URIRef("https://schema.org/isPartOf")
publisher = URIRef("https://schema.org/publisher")
id = URIRef("https://schema.org/identifier") # Used for every identifier
# Attributes related to classes
publicationYear = URIRef("https://dbpedia.org/ontology/year")
title = URIRef("https://schema.org/name")
issue = URIRef("https://schema.org/issueNumber")
volume = URIRef("https://schema.org/volumeNumber")
chapter_num = URIRef("https://schema.org/numberedPosition")
event = URIRef("https://schema.org/event")
author = URIRef("https://schema.org/author")
name = URIRef("https://schema.org/givenName")
surname = URIRef("https://schema.org/familyName")
citation = URIRef("https://schema.org/citation")
class TriplestoreProcessor(object):
def __init__(self):
# 'db_path' is name we use for the database path
self.endpointURL = ""
def getEndpointURL(self):
if self.endpointURL == "":
return "endpointURL is currently unset" + self.endpointURL
def setEndpointURL(self, new_endpointURL):
if new_endpointURL is str:
self.endpointURL = new_endpointURL
return True
else:
return False
# ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
class TriplestoreDataProcessor(TriplestoreProcessor):
def __init__(self):
super().__init__()
def uploadData(self, filepath):
# Step-1 : read the data into pandas
if filepath.endswith(".csv"):
#df1 -> journal article // columns = 'id', 'title', 'type', 'publication_year', 'issue', 'volume'
#df2 -> book-chapter // columns = 'id', 'title', 'type', 'publication_year', 'chapter'
#df3 -> proceedings-paper // columns = 'id', 'title', 'type', 'publication_year'
#df4 -> Venue_book // columns = 'id', 'publication_venue', 'venue_type', 'publisher'
#df5 -> Venue_journal // columns = 'id', 'publication_venue', 'venue_type', 'publisher'
#df6 -> Venue_proceedings-event // columns = 'id', 'publication_venue', 'venue_type', 'publisher', 'event
df1,df2,df3,df4,df5,df6 = readCSV(filepath)
if filepath.endswith(".json"):
#df7 -> authors // columns =
#df8 -> citations // columns =
#df9 -> publishers // columns =
#df10 -> VenueIDs // columns =
df7,df8,df9,df10 = readJSON(filepath)
# Step-2 : iterate over the data to create triples
# Avoid repetition
#2.1 : store triples for publishers
#2.2 : store triples for venues
#2.3 : store triples for authors
#2.4 : store triples for JA
#2.5 : store triples for BC
#2.6 : store triples for PP
# Step-3 : open the connection to the DB and push the triples.
return True
# ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
class TriplestoreQueryProcessor(QueryProcessor,TriplestoreProcessor):
def __init__(self):
super().__init__()
def getPublicationsPublishedInYear(self, year):
QR_1 = pd.DataFrame()
print("don the things here")
return QR_1
def getPublicationsByAuthorId(self, orcid):
QR_2 = pd.DataFrame()
print("don the things here")
return QR_2
def getMostCitedPublication(self):
QR_3 = pd.DataFrame()
print("don the things here")
return QR_3
def getMostCitedVenue(self):
QR_4 = pd.DataFrame()
print("don the things here")
return QR_4
def getVenuesByPublisherId(self, crossref):
QR_5 = pd.DataFrame()
print("don the things here")
return QR_5
def getPublicationInVenue(self, issn_isbn):
QR_6 = pd.DataFrame()
print("don the things here")
return QR_6
def getJournalArticlesInIssue(self, issue, volume, ja_id):
QR_7 = pd.DataFrame()
print("don the things here")
return QR_7
def getJournalArticlesInVolume(self, volume, ja_id):
QR_8 = pd.DataFrame()
print("don the things here")
return QR_8
def getJournalArticlesInJournal(self, ja_id):
QR_9 = pd.DataFrame()
print("don the things here")
return QR_9
def getProceedingsByEvent(self, eventName):
QR_10 = pd.DataFrame()
print("don the things here")
return QR_10
def getPublicationAuthors(self, doi):
QR_11 = pd.DataFrame()
print("don the things here")
return QR_11
def getPublicationsByAuthorName(self, authorName):
QR_12 = pd.DataFrame()
print("don the things here")
return QR_12
def getDistinctPublisherOfPublications(self, doi_list):
QR_13 = pd.DataFrame()
print("don the things here")
return QR_13
# ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
# TEST AREA
grp_endpoint = "http://127.0.0.1:9999/blazegraph/sparql"
grp_dp = TriplestoreDataProcessor()
grp_dp.setEndpointUrl(grp_endpoint)
grp_dp.uploadData("data/graph_publications.csv")
grp_dp.uploadData("data/graph_other_data.json")
# Checking the superclass is correct or not
print(grp_dp.__bases__)
grp_qp = TriplestoreQueryProcessor()
grp_qp.setEndpointUrl(grp_endpoint)
# Checking the superclass is correct or not
print(grp_qp.__bases__)