Commit cad3776a authored by Fabien Amarger's avatar Fabien Amarger
Browse files

feat(fragment): Use hostname to generate fragment

It is used to seperate if same fragment but not same hostname.
For example : schema:Person and foaf:Person
parent 49777c2b22b2
Pipeline #95904 failed with stages
in 1 minute and 36 seconds
......@@ -32,9 +32,9 @@
}
def fragment_from_uri(uri: str) -> Optional[str]:
def fragment_from_uri(uri: str, titling=False) -> Optional[str]:
if uri == OWL.Thing:
return None
url = urlparse(uri)
# if url.fragment is not None, the fragment is done with `#`
if url.fragment:
......@@ -36,11 +36,18 @@
if uri == OWL.Thing:
return None
url = urlparse(uri)
# if url.fragment is not None, the fragment is done with `#`
if url.fragment:
return url.fragment
# otherwise split with `/`
return url.path.split("/")[-1]
fragment = url.fragment
else:
# otherwise split with `/`
fragment = url.path.split("/")[-1]
prefix = ""
if url.hostname is not None:
prefix = url.hostname.replace("www.", "").replace(".", "_") + "_"
if titling:
prefix = prefix.title().replace("_", "")
return f"{prefix}{fragment}"
def yams_domain_from_urirefs(
......@@ -48,7 +55,7 @@
) -> List[str]:
fragments: List[str] = []
for uri in uris:
fragment = fragment_from_uri(uri)
fragment = fragment_from_uri(uri, titling=True)
if fragment is not None:
fragments.append(fragment)
else:
......@@ -72,7 +79,7 @@
# 1. fetch all classes
for class_uri, _, _ in owl_model.triples((None, RDF.type, OWL.Class)):
class_fragment = fragment_from_uri(class_uri)
class_fragment = fragment_from_uri(class_uri, titling=True)
if class_fragment is None:
print(f"Warning: class {class_uri} could not be parsed")
continue
......@@ -88,7 +95,9 @@
for _, _, superior_class_uri in owl_model.triples(
(class_uri, RDFS.subClassOf, None)
):
superior_class_fragment = fragment_from_uri(superior_class_uri)
superior_class_fragment = fragment_from_uri(
superior_class_uri, titling=True
)
if superior_class_fragment is not None:
superior_classes.append(superior_class_fragment)
if superior_classes:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment