Skip to content

Commit

Permalink
updated scholia query parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tholzheim committed May 4, 2024
1 parent 65f2660 commit d786e86
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions tests/test_import_queries.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
import unittest
import urllib.request
import zipfile
from pathlib import Path

import yaml

from nqapi.query import NamedQuery
from tempfile import TemporaryDirectory


class MyTestCase(unittest.TestCase):
@unittest.skip("Only execute if the queries should be regenerated")
def test_something(self):
path = Path("/home/holzheim/Documents/projects/scholia/scholia/app/templates")
exclude = [
"author_topics",
"event_proceedings",
"publisher_editors",
"works_topics",
]
for entry in path.iterdir():
if entry.is_file():
if entry.suffix == ".sparql":
name = entry.stem
if name in exclude:
continue
with open(entry, mode="r") as f:
query_str = f.read()
query = NamedQuery(name=name, query=query_str)
target = Path(__file__).parent.parent.joinpath(
"nqapi", "resources", "queries", f"{name}.yaml"
)
with open(target, mode="w") as f:
f.write(yaml.dump({"name": name, "query": query_str}))
with TemporaryDirectory() as tmpdir:
git_archive = "https://github.com/WDscholia/scholia/archive/refs/heads/master.zip"
path = Path(tmpdir)
zip_file = path.joinpath("master.zip")
urllib.request.urlretrieve(git_archive, path.joinpath("master.zip"))
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
zip_ref.extractall(tmpdir)
query_path = path.joinpath("scholia-master", "scholia/app/templates")
exclude = ["author_topics", "event_proceedings", "publisher_editors", "works_topics", ]
for entry in query_path.iterdir():
if entry.is_file():
if entry.suffix == ".sparql":
name = entry.stem
if name in exclude:
continue
with open(entry, mode="r") as f:
query_str = f.read()
query = NamedQuery(name=name, query=query_str)
target = Path(__file__).parent.parent.joinpath(
"nqapi", "resources", "queries", f"{name}.yaml"
)
with open(target, mode="w") as f:
f.write(yaml.dump({"name": name, "query": query_str}))


if __name__ == "__main__":
Expand Down

0 comments on commit d786e86

Please sign in to comment.