pySHACL | A Python validator for SHACL | Validation library

 by   RDFLib Python Version: 0.25.0 License: Apache-2.0

kandi X-RAY | pySHACL Summary

kandi X-RAY | pySHACL Summary

pySHACL is a Python library typically used in Utilities, Validation, Pytorch applications. pySHACL has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. However pySHACL build file is not available. You can install using 'pip install pySHACL' or download it from GitHub, PyPI.

A Python validator for SHACL. This is a pure Python module which allows for the validation of RDF graphs against Shapes Constraint Language (SHACL) graphs. This module uses the rdflib Python library for working with RDF and is dependent on the OWL-RL Python module for OWL2 RL Profile based expansion of data graphs.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              pySHACL has a low active ecosystem.
              It has 203 star(s) with 60 fork(s). There are 27 watchers for this library.
              There were 3 major release(s) in the last 6 months.
              There are 23 open issues and 116 have been closed. On average issues are closed in 34 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of pySHACL is 0.25.0

            kandi-Quality Quality

              pySHACL has 0 bugs and 0 code smells.

            kandi-Security Security

              pySHACL has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              pySHACL code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              pySHACL is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              pySHACL releases are available to install and integrate.
              Deployable package is available in PyPI.
              pySHACL has no build file. You will be need to create the build yourself to build the component from source.
              Installation instructions, examples and code snippets are available.
              pySHACL saves you 3995 person hours of effort in developing the same functionality from scratch.
              It has 12241 lines of code, 583 functions and 108 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed pySHACL and discovered the below as its top functions. This is intended to give you an instant insight into pySHACL implemented functionality, and help decide if they suit your requirements.
            • Load data from source
            • Get a graph from the web
            • Clone a source graph
            • Clone a dataset
            • Validate the current graph
            • Focus the target nodes
            • Find custom constraints
            • Path of the object
            • Validate a graph
            • Evaluate the target graph
            • Evaluate the constraints
            • Evaluate the constraint on the target graph
            • Validate against the given values
            • Evaluate the graph
            • Evaluate the context on the target graph
            • Evaluate a string rule
            • Applies the filter to the given graph
            • Execute the rule
            • Validate the constraint on the target graph
            • Applies the rule
            • Make a validator for a shape
            • Validate function
            • Return the order of the SHACL shape
            • Execute an expression from a SPARQL expression
            • Binds parameters to the constraint
            • Evaluate the objective function
            Get all kandi verified functions for this library.

            pySHACL Key Features

            No Key Features are available at this moment for pySHACL.

            pySHACL Examples and Code Snippets

            rdfLib turning a single backslash into multiple backslashes
            Pythondot img1Lines of Code : 15dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            ttl = """
                PREFIX sh: 
            
                 sh:pattern "^\s|\d{VALUE}\D" .
                """
            
            g = Graph()
            g.add((
                URIRef("a:"),
                URIRef("http://www.w3.org/ns/shacl#pattern"),
                Literal("^\s|\d{VALUE}\D")
            ))
            g2 = Graph().parse(da
            pySHACL: failure to report validation errors
            Pythondot img2Lines of Code : 6dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            hr:EmployeeShape
               a sh:NodeShape ;
               sh:targetClass hr:Employee ;
               sh:property hr:nameShape ;
               sh:property hr:jobGradeShape .
            

            Community Discussions

            QUESTION

            SHACL SPARQLTarget not validating the SPARQL query output nodes
            Asked 2022-Mar-12 at 10:21

            I have a NodeShape with a sh:SPARQLTarget . I tried to run the Target SPARQL query in an ontology editor and it delivered results, but when I'm executing the same query in my custom target node shape in sh:select, it won't validate the target nodes returned by the SPARQL query. I am using pySHACL. Did I do something wrong? I'm out of ideas. Here is my Nodeshape and data graph:

            I have used “” for sh:select instead of “”” “””, since I am defining the shapes_graph as a variable in my python code and it is already encoded in """ """. I have also enabled meta_shacl=True in pyShacl to ensure that my shapes_graph is valid. Also the nodeShape (snomed:dob363698007Shape) works well when provided with a normal TargetClass or TargetNode. What am I missing?

            I have already referred SPARQLRule not constructing

            ...

            ANSWER

            Answered 2022-Mar-12 at 10:21

            I've put your shacl shapes file and data graph into PySHACL to isolate the issue you are seeing.

            There are two problems with your given setup that I have found.

            Firstly, SPARQL-Based Targets is a feature from the SHACL Advanced Specification. PySHACL does not enable the Advanced-Spec features by default. You can enable "advanced mode" by passing advanced=True to the validation module, or -a or --advanced on the commandline tool.

            That is the main reason your SPARQL target was not selecting the nodes you expected.

            Next, after enabling advanced mode, you will see that PySHACL fails when loading your SHACL Shape Graph. That is because your prefix namespace is not declared correctly.

            See the examples in the SPARQL-Prefixes section of the Spec document. The specification states

            "The values of sh:namespace are literals of datatype xsd:anyURI."

            Your sh:namespace is a URIRef, not a Literal. Changing the namespace declaration to the following, fixes the error.

            Source https://stackoverflow.com/questions/71443139

            QUESTION

            SHACL validate existing domain and range definitions?
            Asked 2022-Jan-22 at 02:23

            I want to validate the existing rdfs:domain and rdfs:range statements of an existing ontology and knowledge base with SHACL. However it seems like it is extremely verbose to do that with SHACL.

            Existing Definition ...

            ANSWER

            Answered 2022-Jan-22 at 02:23

            Let me start by saying that rdfs:domain and rdfs:range are not constraints and don't mean what you imply. They are merely producing inferences. Having said this, many people have in the past used them to "mean" constraints simply because there was no other modeling language. For background, see

            https://www.topquadrant.com/owl-blog/

            If you don't want to duplicate the RDFS triples as individual SHACL constraints, you can write a single generic SHACL shape that has sh:targetSubjectsOf rdfs:domain (and range) and then uses a SPARQL constraint to check that there is no instance of a class other than the domain class that has values for the given property. The end result would be that all rdfs:domain statements would be checked at once.

            But arguably RDFS should be left alone. If you want to use closed-world semantics you should use a language that has been designed for that purpose, i.e. SHACL.

            (BTW there is a Discord group in case you want a higher bandwidth to discuss such things https://twitter.com/HolgerKnublauch/status/1461590465304662019)

            Source https://stackoverflow.com/questions/70787874

            QUESTION

            How to validate literal values with no datatype definition in SHACL?
            Asked 2022-Jan-12 at 00:05

            I assumed that not having any datatype is implicitly the same as having xsd:string as datatype, however SHACL gives me a validation error. Is my assumption wrong or is that just not covered by SHACL? In the latter case, how do I validate that the datatype is either empty or xsd:string?

            string.ttl ...

            ANSWER

            Answered 2022-Jan-12 at 00:05

            In your example the data contains an rdf:langString literal, which is not the same datatype as xsd:string - you see the @en language tag. You probably refer to the fact that the following would be equivalent: "Hello World" and "Hello World"^^xsd:string. So the pyshacl result above looks correct to me.

            Source https://stackoverflow.com/questions/70668384

            QUESTION

            What is the difference between these shape graphs which use sh:or?
            Asked 2020-Apr-22 at 18:09

            I have the following Data Graph.

            ...

            ANSWER

            Answered 2020-Apr-22 at 18:09

            It is important to understand how property paths work. A path is used to reach values. When using sh:path [sh:zeroOrMorePath rdf:path] and considering the node hr:Longer, it will reach three values -- (0) hr:Longer, (1) hr:Employee, and (2) rdfs:Class.

            With this concept firmly in mind, what is going on in (B) and why it does not work can be fully explained.

            Both (A) and (B) have the same target definition and will return the same focus nodes. These are:

            Source https://stackoverflow.com/questions/61323857

            QUESTION

            Validating that every subject has a type of class
            Asked 2020-Apr-16 at 16:33

            I have the following Data & Shape Graph.

            ...

            ANSWER

            Answered 2020-Apr-16 at 16:33

            What follows results in the expected validation errors, however, there are still several things I do not understand.

            1. The sh:prefixes hr: ; is not needed. It is designed to supply prefixes for the SPARQL target SELECT statement itself and nothing more.

            2. Inference needed to be disabled. It was inserting triples and trying to validate them. In this use case, that is not what is desired. What should be validated is what is in the schema and nothing else.

            3. I was also thinking that it would not be an issue to put everything into a single graph based on what apparently was a misunderstanding of https://github.com/RDFLib/pySHACL/issues/46.

            Source https://stackoverflow.com/questions/61190422

            QUESTION

            pySHACL: failure to report validation errors
            Asked 2020-Apr-01 at 16:33

            I have a gist with all of the relevant files at: https://gist.github.com/James-Hudson3010/2588d9b17dd33e15922122b8b5cf1bd7

            If I execute:

            ...

            ANSWER

            Answered 2020-Apr-01 at 12:59

            When you use the individual files, pySHACL has no way of knowing what to associate your Shape file's hr:Employee NodeShape with. It seems to know when it's in that single file (perhaps it runs against all classes in the file??).

            So:

            1. rename the Employee shape to not overload the hr:Employee class name: hr:EmployeeShape
            2. add back in the sh:targetClass directive:

            Source https://stackoverflow.com/questions/60970583

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install pySHACL

            Install with PIP (Using the Python3 pip installer pip3). Or in a python virtualenv (these example commandline instructions are for a Linux/Unix based OS).

            Support

            The SHACL community has a discord server for discussion of topics around SHACL and the SHACL specification. There is a #pyshacl channel in which discussion around this python library can held, and you can ask for general pyshacl help too.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install pyshacl

          • CLONE
          • HTTPS

            https://github.com/RDFLib/pySHACL.git

          • CLI

            gh repo clone RDFLib/pySHACL

          • sshUrl

            git@github.com:RDFLib/pySHACL.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Validation Libraries

            validator.js

            by validatorjs

            joi

            by sideway

            yup

            by jquense

            jquery-validation

            by jquery-validation

            validator

            by go-playground

            Try Top Libraries by RDFLib

            rdflib

            by RDFLibPython

            sparqlwrapper

            by RDFLibPython

            rdflib-jsonld

            by RDFLibPython

            pyLODE

            by RDFLibPython

            rdflib-sqlalchemy

            by RDFLibPython