Commit c7e39927 authored by Élodie Thiéblin's avatar Élodie Thiéblin
Browse files

feat: use official prefix if known

fixes the problem of standard w3.org vocabularies (skos, rdf, rdfs, etc.)
parent a1b6117a1282
import subprocess
import re
import os
import json
from pathlib import Path
import shutil
from typing import Iterable, Optional, List, Dict, Tuple
......@@ -31,6 +32,9 @@
XSD.float: "Float",
}
with open(f"{here}/prefixes.json","r") as fobj:
PREFIXES = json.load(fobj)
def fragment_from_uri(uri: str, titling=False) -> Optional[str]:
if uri == OWL.Thing:
......@@ -43,7 +47,11 @@
# otherwise split with `/`
fragment = url.path.split("/")[-1]
prefix = ""
if url.hostname is not None:
# try to find prefix in list of prefixes
unfragmented_url = uri.rstrip(fragment)
if unfragmented_url in PREFIXES:
prefix = PREFIXES[unfragmented_url] + "_"
elif url.hostname is not None:
prefix = url.hostname.replace("www.", "").replace(".", "_") + "_"
if titling:
prefix = prefix.title().replace("_", "")
......
This diff is collapsed.
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