# baseURI: http://tests.script.topbraid.org/resultsgenerators/resultsgeneratorscript.test

@prefix dash: <http://datashapes.org/dash#> .
@prefix ex: <http://tests.script.topbraid.org/resultsgenerators/resultsgeneratorscript.test#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://tests.script.topbraid.org/resultsgenerators/resultsgeneratorscript.test>
  a owl:Ontology ;
  <http://topbraid.org/swa#defaultNamespace> "http://tests.script.topbraid.org/resultsgenerators/resultsgeneratorscript.test#" ;
  rdfs:label "Tests for dash:ResultsGeneratorScript" ;
  owl:imports <http://datashapes.org/dash> ;
.
ex:MissingLabelResultsGenerator
  a dash:ResultsGeneratorScript ;
  dash:js """let newLabel = graph.qname(focusNode)
graph.update(`
	INSERT {
		$report sh:result ?result .
		?result a dash:SuggestionResult .
		?result sh:focusNode $focusNode .
		?result sh:resultMessage "Missing label" .
		?result sh:resultPath rdfs:label .
		?result dash:suggestion ?suggestion .
		?suggestion a dash:GraphUpdate .
		?suggestion sh:order 0 .
		?suggestion sh:message $message .
		?suggestion dash:suggestionConfidence 100 .
		?suggestion dash:addedTriple ?triple .
		?triple rdf:subject $focusNode .
		?triple rdf:predicate rdfs:label .
		?triple rdf:object $newLabel .
	}
	WHERE {
		BIND (BNODE() AS ?result) .
		BIND (BNODE() AS ?suggestion) .
		BIND (BNODE() AS ?triple) .
	}`, {
		focusNode,
		message: `Add rdfs:label "${newLabel}" to ${focusNode}`,
		newLabel,
		report
	})""" ;
  rdfs:comment "A sample Results generator that adds an rdfs:label for any instance of owl:Thing that doesn't have one yet." ;
  rdfs:label "Missing Label Results Generator" ;
  sh:ask """ASK {
	FILTER NOT EXISTS {
		$this rdfs:label ?label .
	}
	FILTER EXISTS {
		$this rdf:type/rdfs:subClassOf* owl:Thing .
	}
}""" ;
  sh:prefixes <http://datashapes.org/dash> ;
  sh:select """SELECT $this
WHERE {
	$this rdf:type/rdfs:subClassOf* owl:Thing .
	FILTER NOT EXISTS {
		$this rdfs:label ?label .
	}
}""" ;
.
ex:SomeClass
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "Some Class" ;
  rdfs:subClassOf owl:Thing ;
  sh:property ex:SomeClass-label ;
.
ex:SomeClass-label
  a sh:PropertyShape ;
  sh:path rdfs:label ;
  dash:singleLine true ;
  <http://datashapes.org/graphql#name> "labels" ;
  sh:name "labels" ;
  sh:or dash:StringOrLangString ;
.
ex:SomeInstanceWithLabel
  a ex:SomeClass ;
  rdfs:label "Some Instance with Label" ;
.
ex:SomeInstanceWithoutLabel
  a ex:SomeClass ;
.
