Skip to content
Snippets Groups Projects
Commit d6b474e9 authored by Eliott Sammier's avatar Eliott Sammier
Browse files

Improve per-module logging

parent d98e15e4
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ import extract_mosetp
from common import *
# Initialise logger
log = get_logger(__name__)
log = get_logger("extract")
schema_ontology_uri = URIRef(
"http://www.semanticweb.org/eliott/ontologies/2024/4/macao"
......
......@@ -7,7 +7,7 @@ from common import *
from extract_page import parse_page
# Initialise logger
log = get_logger(__name__)
log = get_logger("extract_mosetp")
def generate_triples(
......
......@@ -13,7 +13,7 @@ from typing_extensions import override
from common import *
# Initialise logger
log = get_logger(__name__)
log = get_logger("extract_page")
class Comment:
......
......@@ -2,27 +2,31 @@ from rdflib import OWL, RDF, Graph
from common import *
log = get_logger("transform")
def construct(g: Graph, query: str):
"""Performs a SPARQL `CONSTRUCT` query and add the resulting triples
to the graph, in-place.
"""
:return: Number of *new* triples (i.e. not present in the initial graph)
"""
res = g.query(query)
if res.graph is not None:
g += res.graph
new_triples = res.graph - g
n = len(new_triples)
g += new_triples
if n > 0:
log.info(f"\tConstructed {n} triples")
return n
return 0
def construct_while(g: Graph, query: str):
"""Repeat a CONSTRUCT query, adding triples to the graph, until the query
stops generating new triples"""
while True:
res = g.query(query)
if res.graph is not None and len(res.graph - g) > 0:
print(f"Constructed {len(res.graph - g)} triples")
g += res.graph
else:
break
while construct(g, query) > 0:
pass
def main():
......@@ -32,22 +36,9 @@ def main():
graph.parse(RDF_SCHEMA_FILE)
graph.parse(RDF_CONTENT_FILE)
construct(
graph,
"""
CONSTRUCT {
?exo a :ExerciceQC
} WHERE {
{
?exo a :ExerciceQC_QCU
} UNION {
?exo a :ExerciceQC_QCM
}
}""",
)
# Apply property 'subClassOf' transitively, except on the "fake" class
# hierarchy based on MacaoRoot
log.info("Adding transitive subclasses...")
q_transitive_subclass = """
CONSTRUCT {
?a rdfs:subClassOf ?c
......@@ -60,6 +51,7 @@ def main():
"""
construct_while(graph, q_transitive_subclass)
log.info("Adding supertypes...")
construct_while(
graph,
"""
......@@ -71,18 +63,6 @@ def main():
}
""",
)
# construct(
# graph,
# """
# CONSTRUCT {
# } WHERE {
# ?subj a ?child_type .
# ?child_type rdfs:subClassOf ?parent_type
# }
# """,
# )
# ==> Save
# Remove dependency on previous ontologies
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment