Skip to content
Snippets Groups Projects
Select Git revision
  • 2cecbbcad90bce3d57f482e40820a4cf22a103f0
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

App.js

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