Skip to content
Snippets Groups Projects
Select Git revision
  • 14f744196fb8528a8d63f12e970aff6c04b9fa02
  • main default
  • 35-cgu
  • 34-peertube-support
  • 27-add-autoplay-to-iframe
  • 33-bug-on-youtube-embed-urls
  • RC-Rekall-v1.1-fix_lpo
  • tuleap-140-go-back-to-my-capsules-page-when-i-m-on-capsule-preview-page
  • RC-Rekall-v1.2-fix10
  • RC-Rekall-v1.2-fix9
  • RC-Rekall-v1.2-fix8
  • RC-Rekall-v1.2-fix7
  • RC-Rekall-v1.2-fix6
  • RC-Rekall-v1.2-fix5
  • RC-Rekall-v1.2-fix4
  • RC-Rekall-v1.2-fix3
  • RC-Rekall-v1.2-fix2
  • RC-Rekall-v1.2-fix1
  • RC-Rekall-v1.1-fix-3
  • RC-Rekall-v1.1-fix-2
  • RC-Rekall-v1.1-fix-1
  • RC-Rekall-v1.1-delivered
  • preprod20220209-1535
23 results

symfony.lock

Blame
  • ontology_utils.py 1.23 KiB
    #!/usr/bin/python3.10
    # -*-coding:Utf-8 -*
    
    #==============================================================================
    # Ontology Utilities
    #------------------------------------------------------------------------------
    # --
    #==============================================================================
    
    from rdflib import Graph
    
    def harmonize_prefixes(graph, source_uri, target_uri):
        for s, p, o in graph.triples((None, None, None)):
            s = s if not s.startswith(source_uri) else s.replace(source_uri, target_uri)
            p = p if not p.startswith(source_uri) else p.replace(source_uri, target_uri)
            o = o if not isinstance(o, str) or not o.startswith(source_uri) else o.replace(source_uri, target_uri)
            graph.add((s, p, o))
        return graph
    
    def extract_prefixes_from_graph(graph):
        return {prefix: namespace for prefix, namespace in graph.namespaces()}
    
    def uri_to_short_form(uri, prefix_mappings, graph_prefixes):
        for prefix, *uris in prefix_mappings:
            for u in uris:
                if u in uri:
                    return f"{prefix}:{uri.replace(u, '')}"
        for prefix, namespace in graph_prefixes.items():
            if namespace in uri:
                return f"{prefix}:{uri.replace(namespace, '')}"
        return uri