Search code examples
sparqlrdfowlprotege

SPARQL - Make a Anti pattern query that select the ClassName that respect the CamelCase (No uppercase)


I want to find a query that select the ClassName that doesn't begin with an uppercace. The architecture is:

SELECT DISTINCT ?prop WHERE { { ?prop rdf:type owl:Class . } UNION { ?prop rdf:type owl:DatatypeProperty . } MINUS { #To DO }. }


Solution

  • You can't perform regex directly on your ?prop because it probably contains the prefix and you don't want it.

    First you have to remove the prefix (let's say your prefix is ":")

    bind(strafter(str(?class),str(:)) as ?propertyName)
    

    It will create a var called propertyName that contains only the name (without prefix)

    Now that you have this you can perform regex on it. If you only want to keep properties starting with a capital case you can do:

    FILTER regex(str(?propertyName),"^[A-Z]")
    

    Note: if you want to verify every rules of camelCase you can check this regex