From 01c49901aac2a41e5c06a5c5c0c508ebf69e0922 Mon Sep 17 00:00:00 2001 From: xgaia Date: Wed, 24 Jul 2019 09:25:31 +0200 Subject: [PATCH] remove json file and store prefix in SparqlQuery --- abstractor | 16 ++++------------ libabstractor/SparqlQuery.py | 15 +++++++++++++-- prefixes.json | 11 ----------- setup.py | 4 ++-- 4 files changed, 19 insertions(+), 27 deletions(-) delete mode 100644 prefixes.json diff --git a/abstractor b/abstractor index ca38cb8..a066bff 100644 --- a/abstractor +++ b/abstractor @@ -1,7 +1,6 @@ #! /usr/bin/python3 import argparse -import json import textwrap from libabstractor.SparqlQuery import SparqlQuery @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: diff --git a/libabstractor/SparqlQuery.py b/libabstractor/SparqlQuery.py index dac5018..b9b81c3 100644 --- a/libabstractor/SparqlQuery.py +++ b/libabstractor/SparqlQuery.py @@ -4,7 +4,7 @@ class SparqlQuery(object): """SPARQL methods""" - def __init__(self, endpoint, prefix, prefixes): + def __init__(self, endpoint, prefix): """Init Parameters @@ -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 diff --git a/prefixes.json b/prefixes.json deleted file mode 100644 index b0a9c9e..0000000 --- a/prefixes.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "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/" -} diff --git a/setup.py b/setup.py index ce0b602..e556b6c 100644 --- a/setup.py +++ b/setup.py @@ -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='xavier.garnier@irisa.fr', 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',