Package: semantic-field-definition-generator
Semantic Field Definition GeneratorA generator forMetaphacts/ResearchSpacesemantic field definitions.For background information see:ResearchSpace:https://documentation.researchspace.org/resource/Help:SemanticFormMetaphacts:https://help.metaphacts.com/resource/Help:SemanticFormBased onhttps://github.com/swiss-art-research-net/sari-field-definitions-generatorInstallationinstall using pippipinstallsemantic-field-definition-generatorUsageCommand line toolFor more details on the use of the command line tool runsemantic-field-util -h:usage: semantic-field-util [-h] [--version] [-f {RS,MP,UNI,JSON,INLINE}] -y YAML_FILE
                           [-u SPARQL_URI] [--sparql-repository SPARQL_REPOSITORY]
                           [--sparql-auth-user SPARQL_USER] [--sparql-auth-password SPARQL_PASS]
                           [-t TRIG_FILE] [--field-id-prefix FIELD_PREFIX] [--split-fields]
                           [--add-ns-prefix ADD_NS_PREFIX] [-l {INFO,DEBUG,ERROR}]
                           {read,write}

Utility to convert ResarchSpace/Metaphacts semantic field definitions.

positional arguments:
  {read,write}          Action: read=read semantic field definitions in RDF (SPARQL store or file)
                        and write YAML file, write=read YAML file and write semantic field
                        definitions to RDF TriG file(s)

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -f {RS,MP,UNI,JSON,INLINE}, --flavor {RS,MP,UNI,JSON,INLINE}
                        Flavor of RDF field definitions: RS=ResearchSpace, MP=Metaphacts,
                        UNI=universal, JSON=JSON, INLINE=inline, default=RS
  -y YAML_FILE, --yaml YAML_FILE
                        YAML file (can be directory containing *.yml files) with field definitions
                        to read or write
  -u SPARQL_URI, --sparql-uri SPARQL_URI
                        SPARQL endpoint URI, e.g. http://localhost:8081/sparql
  --sparql-repository SPARQL_REPOSITORY
                        Optional SPARQL repository parameter, default=assets
  --sparql-auth-user SPARQL_USER
                        Optional SPARQL auth username, default=admin
  --sparql-auth-password SPARQL_PASS
                        Optional SPARQL auth password, default=admin
  -t TRIG_FILE, --trig TRIG_FILE
                        RDF TriG file (can be directory containing *.trig files) to read or write
  --field-id-prefix FIELD_PREFIX
                        Optional URL prefix for field ids
  --split-fields        Optional split TriG/YAML output into one file per field (file name = field
                        id)
  --add-ns-prefix ADD_NS_PREFIX
                        Optional additional namespace prefix e.g.
                        skos=http://www.w3.org/2004/02/skos/core# (multiple separated by comma)
  -l {INFO,DEBUG,ERROR}, --log {INFO,DEBUG,ERROR}
                        Log level.Create field definitionsDefine field definitions as a Python dict or in an external YAML file:prefix:http://rs.swissartresearch.net/instances/fields/fields:-id:{unique identifier}label:{label}description:{description}dataType:{datatype}domain:{domain}range:{range}minOccurs:#maxOccurs:#queries:-ask:'{askquery}'-delete:'{deletequery}'-insert:'{insertquery}'-select:'{selectquery}'-valueSet:'{valuesetquery}'-...Then, load and compile it using the thewriteaction of the command line toolsemantic-field-utilsemantic-field-util -f RS -y ./fieldDefinitions.yml write -t ../ldp/assets/fieldDefinitions.trigThis will read the YAML filefieldDefinitions.ymland create ResearchSpace-flavor (-f RS) field definitions in the TriG file../ldp/assets/fieldDefinitions.trig.You can also use the generator library in your Python programfromSemanticFieldDefinitionGeneratorimportgeneratorinputFile='./fieldDefinitions.yml'outputFile='../ldp/assets/fieldDefinitions.trig'model=generator.loadSourceFromFile(inputFile)output=generator.generate(model,generator.METAPHACTS)withopen(outputFile,'w')asf:f.write(output)Available templates are:generator.METAPHACTSfor Metaphacts Open Source Platform (command line flavorMP)generator.RESEARCHSPACEfor ResearchSpace (command line flavorRS)generator.UNIVERSALfor both platforms (command line flavorUNI)generator.JSONfor a JSON representation (command line flavorJSON)generator.INLINEfor a Backend Template version (command line flavorINLINE)Read field definitionsYou can read semantic field definitions in RDF from a SPARQL endpoint or TriG files and create a YAML file in the format shown above using thereadaction of the command line toolsemantic-field-utilsemantic-field-util -f RS read -u http://localhost:8280/sparql -y ./fieldDefinitions.ymlThis will read ResearchSpace-flavor field definitions from the SPARQL endpointhttp://localhost:8080/sparqland create the YAML file./fieldDefinitions.yml.You can also use the parser library in your Python programfromSemanticFieldDefinitionGeneratorimportparsersparql_uri='http://localhost:8080/sparql'outputFile='./fieldDefinitions.yml'store=parser.open_sparql_store(sparql_uri,repository='assets',auth_user='admin',auth_pass='admin')fields=parser.read_fields(store,parser.RESEARCHSPACE)parser.write_fields_yaml(fields,outputfile)LimitationsThe parser currently doesn't support "Tree Patterns".The generator currently doesn't support multiple values for "Domains", "Ranges" and "Default Values".