Using rudof to compare schemas

Using rudof to compare schemas#

Open In Colab

!pip install pyrudof
Collecting pyrudof
  Downloading pyrudof-0.1.135-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.8 kB)
Downloading pyrudof-0.1.135-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.3 MB)
?25l   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/11.3 MB ? eta -:--:--
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.3/11.3 MB 100.5 MB/s  0:00:00
?25h
Installing collected packages: pyrudof
Successfully installed pyrudof-0.1.135
from pyrudof import Rudof, RudofConfig
rudof = Rudof(RudofConfig())

Comparing Schemas#

It is possible to use rudof to compare different schemas. For example:

schema1 = """
 PREFIX : <http://example.org/>
 PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
 :Person {
    :name xsd:string ;
    :age xsd:integer ;
    :weight xsd:float ;
    :worksFor .
 }
""";
schema2 = """
 PREFIX ex: <http://example.org/>
 PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
 ex:Person {
    ex:name xsd:string ;
    ex:birthDate xsd:date ;
    ex:worksFor .
}
"""
result = rudof.compare_schemas_str(
    schema1, schema2,
    "shex", "shex",
    "shexc", "shexc",
    None, None,
    "http://example.org/Person", "http://example.org/Person"
    )
print(f"Result of comparison:\n{result.as_json()}")
Result of comparison:
{
  "equal_properties": {
    "http://example.org/worksFor": {
      "description1": {
        "iri_ref": "http://example.org/worksFor"
      },
      "description2": {
        "iri_ref": "http://example.org/worksFor"
      }
    },
    "http://example.org/name": {
      "description1": {
        "iri_ref": "http://example.org/name",
        "value_constraint": {
          "Datatype": "http://www.w3.org/2001/XMLSchema#string"
        }
      },
      "description2": {
        "iri_ref": "http://example.org/name",
        "value_constraint": {
          "Datatype": "http://www.w3.org/2001/XMLSchema#string"
        }
      }
    }
  },
  "properties1": {
    "http://example.org/age": {
      "description": {
        "iri_ref": "http://example.org/age",
        "value_constraint": {
          "Datatype": "http://www.w3.org/2001/XMLSchema#integer"
        }
      }
    },
    "http://example.org/weight": {
      "description": {
        "iri_ref": "http://example.org/weight",
        "value_constraint": {
          "Datatype": "http://www.w3.org/2001/XMLSchema#float"
        }
      }
    }
  },
  "properties2": {
    "http://example.org/birthDate": {
      "description": {
        "iri_ref": "http://example.org/birthDate",
        "value_constraint": {
          "Datatype": "http://www.w3.org/2001/XMLSchema#date"
        }
      }
    }
  }
}