Skip to content

Commit

Permalink
remove json file and store prefix in SparqlQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
xgaia committed Jul 24, 2019
1 parent a29efc5 commit 01c4990
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
16 changes: 4 additions & 12 deletions abstractor
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#! /usr/bin/python3

import argparse
import json
import textwrap
from libabstractor.SparqlQuery import SparqlQuery

Expand All @@ -22,13 +21,6 @@ class Abstractor(object):

self.args = parser.parse_args()

# Get common prefix from the json file
with open("prefixes.json", "r") as file:
file_content = file.read()

self.prefixes = json.loads(file_content)
self.prefixes[":"] = self.args.prefix

def get_entities_and_relations(self):
"""Get all entities and relations
Expand All @@ -37,7 +29,7 @@ class Abstractor(object):
list, list
header and results
"""
sparql = SparqlQuery(self.args.endpoint, self.args.prefix, self.prefixes)
sparql = SparqlQuery(self.args.endpoint, self.args.prefix)

query = textwrap.dedent('''
SELECT DISTINCT ?entity ?rel ?valueType
Expand All @@ -63,7 +55,7 @@ class Abstractor(object):
list, list
header and results
"""
sparql = SparqlQuery(self.args.endpoint, self.args.prefix, self.prefixes)
sparql = SparqlQuery(self.args.endpoint, self.args.prefix)

query = textwrap.dedent('''
SELECT DISTINCT ?entity ?attr
Expand All @@ -87,7 +79,7 @@ class Abstractor(object):
list, list
header and results
"""
sparql = SparqlQuery(self.args.endpoint, self.args.prefix, self.prefixes)
sparql = SparqlQuery(self.args.endpoint, self.args.prefix)

query = textwrap.dedent('''
SELECT DISTINCT ?entity ?attr
Expand All @@ -106,7 +98,7 @@ class Abstractor(object):

def main(self):
"""main"""
sparql = SparqlQuery(self.args.endpoint, self.args.prefix, self.prefixes)
sparql = SparqlQuery(self.args.endpoint, self.args.prefix)

with open(self.args.output, "w") as file:

Expand Down
15 changes: 13 additions & 2 deletions libabstractor/SparqlQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class SparqlQuery(object):
"""SPARQL methods"""

def __init__(self, endpoint, prefix, prefixes):
def __init__(self, endpoint, prefix):
"""Init
Parameters
Expand All @@ -18,7 +18,18 @@ def __init__(self, endpoint, prefix, prefixes):
"""
self.endpoint = endpoint
self.prefix = prefix
self.prefixes = prefixes
self.prefixes = {
"owl:": "http://www.w3.org/2002/07/owl#",
"rdf:": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfs:": "http://www.w3.org/2000/01/rdf-schema#",
"dc:": "http://purl.org/dc/elements/1.1/",
"prov:": "http://www.w3.org/ns/prov#",
"xsd:": "http://www.w3.org/2001/XMLSchema#",
"skos:": "http://www.w3.org/2004/02/skos/core#",
"chebi:": "http://purl.obolibrary.org/obo/",
"drugbankdrugs:": "http://wifo5-04.informatik.uni-mannheim.de/drugbank/resource/drugs/",
":": self.prefix
}

def get_sparl_prefix(self):
"""Get a SPARQL prefix string
Expand Down
11 changes: 0 additions & 11 deletions prefixes.json

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

setup(
name='abstractor',
version='1.0.4',
version='1.0.5',
description='Abstraction generator for AskOmics, from a distant SPARQL endpoint',
author='Xavier Garnier',
author_email='[email protected]',
url='https://github.com/xgaia/abstractor',
download_url='https://github.com/xgaia/abstractor/archive/1.0.4.tar.gz',
download_url='https://github.com/xgaia/abstractor/archive/1.0.5.tar.gz',
install_requires=['SPARQLWrapper'],
packages=find_packages(),
license='AGPL',
Expand Down

0 comments on commit 01c4990

Please sign in to comment.