# baseURI: http://onto.fel.cvut.cz/ontologies/mindmaps/task/inbas-scripts
# imports: http://onto.fel.cvut.cz/ontologies/mindmaps/task/inbas
# imports: http://topbraid.org/sparqlmotionfunctions
# imports: http://topbraid.org/sparqlmotionlib-tbc
# prefix: inbas-scripts

@prefix arg: <http://spinrdf.org/arg#> .
@prefix inbas-scripts: <http://onto.fel.cvut.cz/ontologies/mindmaps/task/inbas-scripts#> .
@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 search: <http://topbraid.org/search#> .
@prefix sm: <http://topbraid.org/sparqlmotion#> .
@prefix smf: <http://topbraid.org/sparqlmotionfunctions#> .
@prefix sml: <http://topbraid.org/sparqlmotionlib#> .
@prefix sp: <http://spinrdf.org/sp#> .
@prefix spin: <http://spinrdf.org/spin#> .
@prefix spl: <http://spinrdf.org/spl#> .
@prefix task: <http://onto.fel.cvut.cz/ontologies/mindmaps/task/> .
@prefix ui: <http://uispin.org/ui#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

task:TestTemplate
  rdf:type spin:ConstructTemplate ;
  spin:body [
      rdf:type sp:Construct ;
      sp:templates (
          [
            sp:object [
                sp:varName "mindmapIRI"^^xsd:string ;
              ] ;
            sp:predicate rdfs:label ;
            sp:subject [
                sp:varName "hookNode"^^xsd:string ;
              ] ;
          ]
        ) ;
      sp:where (
          [
            rdf:type sp:NamedGraph ;
            sp:elements (
                [
                  sp:object [
                      sp:varName "hookNodeLabel"^^xsd:string ;
                    ] ;
                  sp:predicate <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#TEXT-node> ;
                  sp:subject [
                      sp:varName "hookNode"^^xsd:string ;
                    ] ;
                ]
              ) ;
            sp:graphNameNode [
                sp:varName "mindmapIRI"^^xsd:string ;
              ] ;
          ]
        ) ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:hookNodeLabel ;
      spl:valueType xsd:string ;
      rdfs:comment "Label of node to which taxonomical nodes should be attached."^^xsd:string ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:mindmapIRI ;
      spl:valueType rdfs:Resource ;
      rdfs:comment "IRI of mindmap to be updated."^^xsd:string ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:taxRootClassIRI ;
      spl:valueType rdfs:Resource ;
      rdfs:comment "Root class IRI of an ontological taxonomy."^^xsd:string ;
    ] ;
  spin:labelTemplate "Constructs attachement of ?{taxRootClassIRI} taxonomy to node of mindmap ?{mindmapIRI} with label ?{hookNodeLabel}."^^xsd:string ;
  rdfs:subClassOf task:MindmapConstructTemplates ;
.
task:inbas-scripts
  rdf:type owl:Ontology ;
  owl:imports task:inbas ;
  owl:imports <http://topbraid.org/sparqlmotionfunctions> ;
  owl:imports <http://topbraid.org/sparqlmotionlib-tbc> ;
  owl:versionInfo "Created with TopBraid Composer"^^xsd:string ;
.
inbas-scripts:BindMindmap
  rdf:type sml:BindWithConstant ;
  sm:next inbas-scripts:MergeMindmapSelection ;
  sm:outputVariable "mindmapIRI"^^xsd:string ;
  sml:value <file:///inbas/extract/freeplane/main.xml> ;
  rdfs:label "Bind mindmap"^^xsd:string ;
.
inbas-scripts:BindTaskAttributes
  rdf:type sml:BindBySelect ;
  sm:nodeX 200 ;
  sm:nodeY 196 ;
  sml:selectQuery [
      rdf:type sp:Select ;
      sp:resultVariables (
          [
            sp:varName "sourceOntologyIRI"^^xsd:string ;
          ]
          [
            sp:varName "ignoreImports"^^xsd:string ;
          ]
        ) ;
      sp:text """SELECT   ?sourceOntologyIRI ?ignoreImports
 WHERE {
   GRAPH <file:///inbas/extract/freeplane/main.xml> {
     BIND(STRDT(task:mm-get-node-attribute-value(?taskNode, \"ignoreImports\"), xsd:boolean) as ?ignoreImports)
     BIND(iri(task:mm-get-node-attribute-value(?taskNode, \"sourceOntologyIRI\")) as ?sourceOntologyIRI)
   }
}"""^^xsd:string ;
      sp:where (
          [
            rdf:type sp:NamedGraph ;
            sp:elements (
                [
                  rdf:type sp:Bind ;
                  sp:expression [
                      rdf:type sp:strdt ;
                      sp:arg1 [
                          rdf:type task:mm-get-node-attribute-value ;
                          arg:a1_mindmapNode [
                              sp:varName "taskNode"^^xsd:string ;
                            ] ;
                          arg:attributeName "ignoreImports" ;
                        ] ;
                      sp:arg2 xsd:boolean ;
                    ] ;
                  sp:variable [
                      sp:varName "ignoreImports"^^xsd:string ;
                    ] ;
                ]
                [
                  rdf:type sp:Bind ;
                  sp:expression [
                      rdf:type sp:iri ;
                      sp:arg1 [
                          rdf:type task:mm-get-node-attribute-value ;
                          arg:a1_mindmapNode [
                              sp:varName "taskNode"^^xsd:string ;
                            ] ;
                          arg:attributeName "sourceOntologyIRI" ;
                        ] ;
                    ] ;
                  sp:variable [
                      sp:varName "sourceOntologyIRI"^^xsd:string ;
                    ] ;
                ]
              ) ;
            sp:graphNameNode <file:///inbas/extract/freeplane/main.xml> ;
          ]
        ) ;
    ] ;
  rdfs:label "Bind task attributes"^^xsd:string ;
.
inbas-scripts:BindTropeHookNode
  rdf:type sml:BindWithConstant ;
  sm:next inbas-scripts:Merge ;
  sm:outputVariable "hookNode"^^xsd:string ;
  sml:value [
      rdf:type task:mm-find-node-by-label ;
      arg:mindmapIRI [
          sp:varName "mindmapIRI"^^xsd:string ;
        ] ;
      arg:nodeLabel "attribute taxonomy" ;
    ] ;
  rdfs:label "Bind trope hook node"^^xsd:string ;
.
inbas-scripts:BindTropeHookNode_Clone
  rdf:type sml:BindWithConstant ;
  sm:next inbas-scripts:Merge ;
  sm:outputVariable "hookNode"^^xsd:string ;
  sml:value [
      rdf:type task:mm-find-node-by-label ;
      arg:mindmapIRI [
          sp:varName "mindmapIRI"^^xsd:string ;
        ] ;
      arg:nodeLabel "object taxonomy" ;
    ] ;
  rdfs:label "Bind object hook node"^^xsd:string ;
.
inbas-scripts:BindTropeHookNode_Clone_Clone
  rdf:type sml:BindWithConstant ;
  sm:next inbas-scripts:Merge ;
  sm:outputVariable "hookNode"^^xsd:string ;
  sml:value [
      rdf:type task:mm-find-node-by-label ;
      arg:mindmapIRI [
          sp:varName "mindmapIRI"^^xsd:string ;
        ] ;
      arg:nodeLabel "event taxonomy" ;
    ] ;
  rdfs:label "Bind event hook node"^^xsd:string ;
.
inbas-scripts:ConstructEventNodes
  rdf:type sml:ApplyConstruct ;
  sm:next inbas-scripts:UpdateMindmap ;
  sml:constructQuery [
      rdf:type task:ConstructAttachableTaxonomiesCT ;
      arg:hookNodeLabel "event taxonomy"^^xsd:string ;
      arg:mindmapIRI <file:///inbas/extract/freeplane/main.xml> ;
      arg:taxRootClassIRI <http://onto.fel.cvut.cz/ontologies/ufo/Event> ;
    ] ;
  sml:replace "true"^^xsd:boolean ;
  rdfs:label "Construct event nodes"^^xsd:string ;
.
inbas-scripts:ConstructObjectNodes
  rdf:type sml:ApplyConstruct ;
  sm:next inbas-scripts:UpdateMindmap ;
  sml:constructQuery [
      rdf:type task:ConstructAttachableTaxonomiesCT ;
      arg:hookNodeLabel "object taxonomy"^^xsd:string ;
      arg:mindmapIRI <file:///inbas/extract/freeplane/main.xml> ;
      arg:taxRootClassIRI <http://onto.fel.cvut.cz/ontologies/ufo/Object> ;
    ] ;
  sml:replace "true"^^xsd:boolean ;
  rdfs:label "Construct object nodes"^^xsd:string ;
.
inbas-scripts:ConstructTropeNodes
  rdf:type sml:ApplyConstruct ;
  sm:next inbas-scripts:UpdateMindmap ;
  sml:constructQuery [
      rdf:type task:ConstructAttachableTaxonomiesCT ;
      arg:hookNodeLabel "attribute taxonomy"^^xsd:string ;
      arg:mindmapIRI <file:///inbas/extract/freeplane/main.xml> ;
      arg:taxRootClassIRI <http://onto.fel.cvut.cz/ontologies/ufo/Trope> ;
    ] ;
  sml:replace "true"^^xsd:boolean ;
  rdfs:label "Construct trope nodes"^^xsd:string ;
.
inbas-scripts:FacetValue_1
  rdf:type search:FacetValue ;
  rdfs:label "Facet value 1"^^xsd:string ;
.
inbas-scripts:ImportAviationOntology
  rdf:type sml:ImportRDFFromWorkspace ;
  sm:next inbas-scripts:BindMindmap ;
  sm:next inbas-scripts:ConstructEventNodes ;
  sm:next inbas-scripts:ConstructObjectNodes ;
  sm:next inbas-scripts:ConstructTropeNodes ;
  sm:next inbas-scripts:SelectMindmap ;
  sm:next inbas-scripts:convertRDFToTextTest ;
  sml:baseURI "http://onto.fel.cvut.cz/ontologies/aviation"^^xsd:string ;
  sml:ignoreImports "false"^^xsd:boolean ;
  rdfs:label "Import aviation ontology"^^xsd:string ;
.
inbas-scripts:Merge
  rdf:type sml:Merge ;
  rdfs:label "Merge"^^xsd:string ;
.
inbas-scripts:MergeMindmapSelection
  rdf:type sml:Merge ;
  sm:next inbas-scripts:BindTropeHookNode ;
  sm:next inbas-scripts:BindTropeHookNode_Clone ;
  sm:next inbas-scripts:BindTropeHookNode_Clone_Clone ;
  rdfs:label "Merge"^^xsd:string ;
.
inbas-scripts:MindmapProcessingModules
  rdf:type sm:Module ;
  spin:abstract "true"^^xsd:boolean ;
  rdfs:label "Mindmap processing"^^xsd:string ;
  rdfs:subClassOf sml:ProcessingModules ;
.
inbas-scripts:PickTaskNodeFromLaunchIcon
  rdf:type sml:BindBySelect ;
  sm:next inbas-scripts:BindTaskAttributes ;
  sm:nodeX 206 ;
  sm:nodeY 29 ;
  sml:selectQuery [
      rdf:type sp:Select ;
      sp:resultVariables (
          [
            sp:varName "taskNode"^^xsd:string ;
          ]
        ) ;
      sp:text """SELECT ?taskNode  
 WHERE {
   GRAPH <file:///inbas/extract/freeplane/main.xml> {
       BIND (task:mm-find-node-by-launch-icon() AS ?taskNode) .
   }
}"""^^xsd:string ;
      sp:where (
          [
            rdf:type sp:NamedGraph ;
            sp:elements (
                [
                  rdf:type sp:Bind ;
                  sp:expression [
                      rdf:type task:mm-find-node-by-launch-icon ;
                    ] ;
                  sp:variable [
                      sp:varName "taskNode"^^xsd:string ;
                    ] ;
                ]
              ) ;
            sp:graphNameNode <file:///inbas/extract/freeplane/main.xml> ;
          ]
        ) ;
    ] ;
  rdfs:label "Pick task node from launch icon"^^xsd:string ;
.
inbas-scripts:Resource_1
  rdf:type rdfs:Resource ;
  rdfs:label "Resource 1"^^xsd:string ;
.
inbas-scripts:SelectMindmap
  rdf:type sml:SelectResource ;
  sm:next inbas-scripts:MergeMindmapSelection ;
  sm:outputVariable "mindmapIRI"^^xsd:string ;
  sml:selectQuery [
      rdf:type sp:Select ;
      sp:text """SELECT *
WHERE { }
VALUES (?mindmapIRIToChoose) {
    (<file:///inbas/extract/freeplane/main.xml>)
}
"""^^xsd:string ;
      sp:values [
          sp:bindings (
              (
                <file:///inbas/extract/freeplane/main.xml>
              )
            ) ;
          sp:varNames (
              "mindmapIRIToChoose"^^xsd:string
            ) ;
        ] ;
      sp:where () ;
    ] ;
  sml:title "Select Mindmap IRI that will be modified."^^xsd:string ;
  rdfs:label "Select mindmap"^^xsd:string ;
.
inbas-scripts:UpdateMindmap
  rdf:type sml:PerformUpdate ;
  sml:updateQuery [
      rdf:type sp:Modify ;
      sp:insertPattern (
          [
            rdf:type sp:NamedGraph ;
            sp:elements (
                [
                  sp:object [
                      sp:varName "o"^^xsd:string ;
                    ] ;
                  sp:predicate [
                      sp:varName "p"^^xsd:string ;
                    ] ;
                  sp:subject [
                      sp:varName "s"^^xsd:string ;
                    ] ;
                ]
              ) ;
            sp:graphNameNode <file:///inbas/extract/freeplane/main.xml> ;
          ]
        ) ;
      sp:text """INSERT {
    GRAPH <file:///inbas/extract/freeplane/main.xml> {
        ?s ?p ?o .
    } .
}
WHERE {
    ?s ?p ?o .
}"""^^xsd:string ;
      sp:where (
          [
            sp:object [
                sp:varName "o"^^xsd:string ;
              ] ;
            sp:predicate [
                sp:varName "p"^^xsd:string ;
              ] ;
            sp:subject [
                sp:varName "s"^^xsd:string ;
              ] ;
          ]
        ) ;
    ] ;
  rdfs:label "Update mindmap "^^xsd:string ;
.
inbas-scripts:convertRDFToTextTest
  rdf:type smf:convertRDFToText ;
  sm:outputVariable "result"^^xsd:string ;
  rdfs:label "convert RDFTo text test"^^xsd:string ;
.
