<jupyter_start><jupyter_text>-ss - use the SparqlSlurper    -sq - a query to find the first 100 items that are instances of wd:Q7397    http://query.wikidata.org/sparql -- Wikidata SPARQL endpoint    https://raw.githubusercontent.com/shexSpec/schemas/master/Wikidata/DigitalPreservation/SWIB/software.shex - ShEx    --stopafter 1 -- only process one node (testing)    -ps -- Print SPARQL queries<jupyter_code>from pyshex.shex_evaluator import evaluate_cli as shexeval
from pyshex import shex_evaluator
from sparqlslurper import SlurpyGraph
from pyshex.user_agent import SlurpyGraphWithAgent
permagraph = None

def persistent_slurper(rdf: str, *args, **kwargs) -> SlurpyGraph:
    global permagraph
    permagraph = SlurpyGraphWithAgent(rdf, *args, **kwargs)
    return permagraph

shex_evaluator.SlurpyGraphWithAgent = persistent_slurper

sparql_query = """
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>

SELECT DISTINCT ?item WHERE {?work wdt:P50 / (wdt:P108 | wdt:P463 | (wdt:P1416/wdt:P361*)) wd:Q27177633. ?item wdt:P2860 ?work.} LIMIT 1
"""
# shexeval(['-h'])

x = ["-ss",
     #"-s",  "http://example.org/disease",
     "-sq", sparql_query,
     "http://query.wikidata.org/sparql",
     "https://raw.githubusercontent.com/kg-subsetting/biohackathon2020/main/use_cases/scholia/organization-numOfRequests-problem.shex",
     #"--stopafter", "1",
     "-ps"]
shexeval(x)
print()
print("RESULT Graph:")
print(permagraph.serialize(format="turtle").decode())<jupyter_output>SPARQL:

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>

SELECT DISTINCT ?item WHERE {?work wdt:P50 / (wdt:P108 | wdt:P463 | (wdt:P1416/wdt:P361*)) wd:Q27177633. ?item wdt:P2860 ?work.} LIMIT 1

ANTLR runtime and generated code versions disagree: 4.8!=4.7.1
ANTLR runtime and generated code versions disagree: 4.8!=4.7.1
SPARQL: (SELECT ?s ?p ?o {<http://www.wikidata.org/entity/Q21129387> ?p ?o}) (0.56 secs) - 427 triples
SPARQL: (SELECT ?s ?p ?o {<http://www.wikidata.org/entity/Q52167010> <http://www.wikidata.org/prop/direct/P31> ?o}) (0.19 secs) - 1 triples
SPARQL: (SELECT ?s ?p ?o {<http://www.wikidata.org/entity/Q52167010> <http://www.wikidata.org/prop/direct/P50> ?o}) (0.43 secs) - 0 triples
SPARQL: (SELECT ?s ?p ?o {<http://www.wikidata.org/entity/Q52167010> <http://www.wikidata.org/prop/direct/P921> ?o}) (0.35 secs) - 0 triples
SPARQL: (SELECT ?s ?p ?o {<http://www.wikidata.org/entity/Q52167010> <http://www.wikidata.org/prop/direct/[...]
{'fraction_non_alphanumeric': 0.1652827204428628, 'fraction_numerical': 0.05693950177935943, 'mean_word_length': 4.405982905982906, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 13, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '343143', 'license': 'MIT', 'n_tokens_mistral': 1094, 'n_tokens_neox': 998, 'n_words': 201, 'path': 'use_cases/scholia/scholia-shex-slurper.ipynb', 'repo_name': 'kg-subsetting/biohackathon2020', 'size': '2529'}