Skip to content

Shacler failing for project specific schema

Nicola Stoira requested to merge issue-18 into master

When a project specific schema is passed we call

projectGraph, _ = loadGraph(path=project_schema, schema_file_type=schema_file_type)

In this case the namespace variable which is added to the return in the latest changes is not defined and therefore the generation fails.

From the fact that this variable is not used once returned we could defined a default value for the namespace. For the moment I configured:

namespace = ('sphn', URIRef('https://biomedit.ch/rdf/sphn-schema/sphn#'))

The loadGraph method should define it correctly when extracting it for the SPHN schema:

def loadGraph(path:str, schema_file_type:Optional[str]) -> tuple:
    """
    loadGraph loads provided input into an rdflib Graph. 

    Args:
        path (str): filepath
        schema_file_type (Optional[str]): file type of file passed to funtion

    Returns:
        tuple[Graph, URIRef]: returns the Graph and the associated OWL.Schema schema namespace
    """
    g = Graph()
    namespace = ('sphn', URIRef('https://biomedit.ch/rdf/sphn-schema/sphn#'))
    if schema_file_type is None:
        try:
            g.parse(str(path))
            for subject,*_ in g.triples((None,None,OWL.Ontology)):
                subject = subject+"#"
                for name_space_prefix, uri_ref in g.namespaces():
                    if URIRef(uri_ref) == subject:
                        namespace = (name_space_prefix,  subject)
        except:
            logger.error("The file type guessed from the extension seems to be wrong. Try to explicitly state the file type of the schema.")
    else:
        try:
            logger.info("Trying to parse: " + str(path) + " in format " + schema_file_type)
            g.parse(str(path), format=schema_file_type)
            for subject,*_ in g.triples((None,None,OWL.Ontology)):
                subject = subject+"#"
                for name_space_prefix, uri_ref in g.namespaces():
                    if URIRef(uri_ref) == subject:
                        namespace = (name_space_prefix,  subject)

        except:
            logger.error("The file parsing fails, maybe you specified the wrong file type?")
    # g = applyNamespaces(g, namespaces) Caused the default error to appear, what do you mean override namespace = True?
    return g, namespace

Merge request reports