# baseURI: http://onto.fel.cvut.cz/ontologies/mindmaps/task/inbas
# imports: http://onto.fel.cvut.cz/ontologies/mindmaps/task

@prefix arg: <http://spinrdf.org/arg#> .
@prefix inb-task: <http://onto.fel.cvut.cz/ontologies/mindmaps/task/inbas/> .
@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 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 xsd: <http://www.w3.org/2001/XMLSchema#> .

task:ConstructAttachableTaxonomies3CT
  rdf:type spin:ConstructTemplate ;
  spin:body [
      rdf:type sp:Construct ;
      sp:templates (
          [
            sp:object <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#Node> ;
            sp:predicate rdf:type ;
            sp:subject [
                sp:varName "subNode"^^xsd:string ;
              ] ;
          ]
          [
            sp:object [
                sp:varName "subLink"^^xsd:string ;
              ] ;
            sp:predicate <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#LINK-node> ;
            sp:subject [
                sp:varName "subNode"^^xsd:string ;
              ] ;
          ]
          [
            sp:object [
                sp:varName "label"^^xsd:string ;
              ] ;
            sp:predicate <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#TEXT-node> ;
            sp:subject [
                sp:varName "subNode"^^xsd:string ;
              ] ;
          ]
          [
            sp:object [
                sp:varName "subNode"^^xsd:string ;
              ] ;
            sp:predicate <http://www.topbraid.org/2007/05/composite.owl#child> ;
            sp:subject [
                sp:varName "superNode"^^xsd:string ;
              ] ;
          ]
          [
            sp:object <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#Node> ;
            sp:predicate rdf:type ;
            sp:subject [
                sp:varName "taxRootNode"^^xsd:string ;
              ] ;
          ]
          [
            sp:object [
                sp:varName "taxRootLabel"^^xsd:string ;
              ] ;
            sp:predicate <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#TEXT-node> ;
            sp:subject [
                sp:varName "taxRootNode"^^xsd:string ;
              ] ;
          ]
          [
            sp:object [
                sp:varName "taxRootLink"^^xsd:string ;
              ] ;
            sp:predicate <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#LINK-node> ;
            sp:subject [
                sp:varName "taxRootNode"^^xsd:string ;
              ] ;
          ]
          [
            sp:object [
                sp:varName "taxRootNode"^^xsd:string ;
              ] ;
            sp:predicate <http://www.topbraid.org/2007/05/composite.owl#child> ;
            sp:subject [
                sp:varName "hookNode"^^xsd:string ;
              ] ;
          ]
        ) ;
      sp:text """CONSTRUCT {
    ?subNode a fp:Node .
    ?subNode fp:LINK-node ?subLink .
    ?subNode fp:TEXT-node ?label .
    ?superNode composite:child ?subNode .
    ?taxRootNode a fp:Node .
    ?taxRootNode fp:TEXT-node ?taxRootLabel .
    ?taxRootNode fp:LINK-node ?taxRootLink .
    ?hookNode composite:child ?taxRootNode .
}
WHERE {
    ?subClass (rdfs:subClassOf)+ ?taxRootClassIRI .
    ?subClass rdfs:subClassOf ?superClass .
    OPTIONAL {
        ?subClass rdfs:label ?label .
        FILTER ( lang(?label) = ?labelLanguage ||  lang(?label) = \"\"  )
    } .
   OPTIONAL {
        ?taxRootClassIRI rdfs:label ?taxRootLabel .
        FILTER ( lang(?taxRootLabel) = ?labelLanguage ||  lang(?taxRootLabel) = \"\" )
    } .
    BIND (task:o2mm-create-node(?subClass) AS ?subNode) .
    BIND (task:o2mm-create-node(?superClass) AS ?superNode) .
    BIND (task:o2mm-create-node(?taxRootClassIRI) AS ?taxRootNode) .
    BIND (str(?subClass) AS ?subLink) .
    BIND (str(?superClass) AS ?superLink) .
    BIND (str(?taxRootClassIRI) AS ?taxRootLink) .
    FILTER (!isBlank(?superClass)) .
    FILTER (!isBlank(?subClass)) .
}"""^^xsd:string ;
      sp:where (
          [
            rdf:type sp:TriplePath ;
            sp:object [
                sp:varName "taxRootClassIRI"^^xsd:string ;
              ] ;
            sp:path [
                rdf:type sp:ModPath ;
                sp:modMax -2 ;
                sp:modMin 1 ;
                sp:subPath rdfs:subClassOf ;
              ] ;
            sp:subject [
                sp:varName "subClass"^^xsd:string ;
              ] ;
          ]
          [
            sp:object [
                sp:varName "superClass"^^xsd:string ;
              ] ;
            sp:predicate rdfs:subClassOf ;
            sp:subject [
                sp:varName "subClass"^^xsd:string ;
              ] ;
          ]
          [
            rdf:type sp:Optional ;
            sp:elements (
                [
                  sp:object [
                      sp:varName "label"^^xsd:string ;
                    ] ;
                  sp:predicate rdfs:label ;
                  sp:subject [
                      sp:varName "subClass"^^xsd:string ;
                    ] ;
                ]
                [
                  rdf:type sp:Filter ;
                  sp:expression [
                      rdf:type sp:or ;
                      sp:arg1 [
                          rdf:type sp:eq ;
                          sp:arg1 [
                              rdf:type sp:lang ;
                              sp:arg1 [
                                  sp:varName "label"^^xsd:string ;
                                ] ;
                            ] ;
                          sp:arg2 [
                              sp:varName "labelLanguage"^^xsd:string ;
                            ] ;
                        ] ;
                      sp:arg2 [
                          rdf:type sp:eq ;
                          sp:arg1 [
                              rdf:type sp:lang ;
                              sp:arg1 [
                                  sp:varName "label"^^xsd:string ;
                                ] ;
                            ] ;
                          sp:arg2 "" ;
                        ] ;
                    ] ;
                ]
              ) ;
          ]
          [
            rdf:type sp:Optional ;
            sp:elements (
                [
                  sp:object [
                      sp:varName "taxRootLabel"^^xsd:string ;
                    ] ;
                  sp:predicate rdfs:label ;
                  sp:subject [
                      sp:varName "taxRootClassIRI"^^xsd:string ;
                    ] ;
                ]
                [
                  rdf:type sp:Filter ;
                  sp:expression [
                      rdf:type sp:or ;
                      sp:arg1 [
                          rdf:type sp:eq ;
                          sp:arg1 [
                              rdf:type sp:lang ;
                              sp:arg1 [
                                  sp:varName "taxRootLabel"^^xsd:string ;
                                ] ;
                            ] ;
                          sp:arg2 [
                              sp:varName "labelLanguage"^^xsd:string ;
                            ] ;
                        ] ;
                      sp:arg2 [
                          rdf:type sp:eq ;
                          sp:arg1 [
                              rdf:type sp:lang ;
                              sp:arg1 [
                                  sp:varName "taxRootLabel"^^xsd:string ;
                                ] ;
                            ] ;
                          sp:arg2 "" ;
                        ] ;
                    ] ;
                ]
              ) ;
          ]
          [
            rdf:type sp:Bind ;
            sp:expression [
                rdf:type task:o2mm-create-node ;
                arg:ontReference [
                    sp:varName "subClass"^^xsd:string ;
                  ] ;
              ] ;
            sp:variable [
                sp:varName "subNode"^^xsd:string ;
              ] ;
          ]
          [
            rdf:type sp:Bind ;
            sp:expression [
                rdf:type task:o2mm-create-node ;
                arg:ontReference [
                    sp:varName "superClass"^^xsd:string ;
                  ] ;
              ] ;
            sp:variable [
                sp:varName "superNode"^^xsd:string ;
              ] ;
          ]
          [
            rdf:type sp:Bind ;
            sp:expression [
                rdf:type task:o2mm-create-node ;
                arg:ontReference [
                    sp:varName "taxRootClassIRI"^^xsd:string ;
                  ] ;
              ] ;
            sp:variable [
                sp:varName "taxRootNode"^^xsd:string ;
              ] ;
          ]
          [
            rdf:type sp:Bind ;
            sp:expression [
                rdf:type sp:str ;
                sp:arg1 [
                    sp:varName "subClass"^^xsd:string ;
                  ] ;
              ] ;
            sp:variable [
                sp:varName "subLink"^^xsd:string ;
              ] ;
          ]
          [
            rdf:type sp:Bind ;
            sp:expression [
                rdf:type sp:str ;
                sp:arg1 [
                    sp:varName "superClass"^^xsd:string ;
                  ] ;
              ] ;
            sp:variable [
                sp:varName "superLink"^^xsd:string ;
              ] ;
          ]
          [
            rdf:type sp:Bind ;
            sp:expression [
                rdf:type sp:str ;
                sp:arg1 [
                    sp:varName "taxRootClassIRI"^^xsd:string ;
                  ] ;
              ] ;
            sp:variable [
                sp:varName "taxRootLink"^^xsd:string ;
              ] ;
          ]
          [
            rdf:type sp:Filter ;
            sp:expression [
                rdf:type sp:not ;
                sp:arg1 [
                    rdf:type sp:isBlank ;
                    sp:arg1 [
                        sp:varName "superClass"^^xsd:string ;
                      ] ;
                  ] ;
              ] ;
          ]
          [
            rdf:type sp:Filter ;
            sp:expression [
                rdf:type sp:not ;
                sp:arg1 [
                    rdf:type sp:isBlank ;
                    sp:arg1 [
                        sp:varName "subClass"^^xsd:string ;
                      ] ;
                  ] ;
              ] ;
          ]
        ) ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:defaultValue "en"^^xsd:string ;
      spl:optional "true"^^xsd:boolean ;
      spl:predicate arg:labelLanguage ;
      spl:valueType xsd:string ;
      rdfs:comment """Determines labels of which language should be shown in nodes. Possible values are \"\", \"en\", \"cs\", ...
Default value is \"en\", while \"\" language is shown as well. """^^xsd:string ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:hookNode ;
      spl:valueType rdfs:Resource ;
      rdfs:comment "IRI of mindmap node to which we should hook the taxonomy."^^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:label "Attach taxonomies CT"^^xsd:string ;
  rdfs:subClassOf task:MindmapConstructTemplates ;
.
task:inbas
  rdf:type owl:Ontology ;
  owl:imports <http://onto.fel.cvut.cz/ontologies/mindmaps/task> ;
  owl:versionInfo "Created with TopBraid Composer"^^xsd:string ;
.
inb-task:attach-events
  rdf:type task:AttachTaxonomiesTask ;
  rdfs:label "attach-events"^^xsd:string ;
.
task:mm-find-node-by-launch-icon
  rdf:type spin:Function ;
  spin:body [
      rdf:type sp:Select ;
      sp:resultVariables (
          [
            sp:varName "mindmapNode"^^xsd:string ;
          ]
        ) ;
      sp:text """SELECT ?mindmapNode
WHERE {
    ?mindmapNode composite:child _:0 .
    _:0 a fp:Icon .
    _:0 fp:bUILTIN \"launch\"^^xsd:string .
}"""^^xsd:string ;
      sp:where (
          [
            sp:object [
                sp:varName "?0"^^xsd:string ;
              ] ;
            sp:predicate <http://www.topbraid.org/2007/05/composite.owl#child> ;
            sp:subject [
                sp:varName "mindmapNode"^^xsd:string ;
              ] ;
          ]
          [
            sp:object <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#Icon> ;
            sp:predicate rdf:type ;
            sp:subject [
                sp:varName "?0"^^xsd:string ;
              ] ;
          ]
          [
            sp:object "launch"^^xsd:string ;
            sp:predicate <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#bUILTIN> ;
            sp:subject [
                sp:varName "?0"^^xsd:string ;
              ] ;
          ]
        ) ;
    ] ;
  rdfs:comment "Find mindmap node that has launch icon."^^xsd:string ;
  rdfs:subClassOf task:MindmapFunctions ;
.
task:mm-get-node-attribute-value
  rdf:type spin:Function ;
  spin:body [
      rdf:type sp:Select ;
      sp:resultVariables (
          [
            sp:varName "attributeValue"^^xsd:string ;
          ]
        ) ;
      sp:text """SELECT ?attributeValue
WHERE {
GRAPH <file:///inbas/extract/freeplane/main.xml> {
    ?a1_mindmapNode composite:child _:0 .
    _:0 a fp:Attribute .
    _:0 fp:nAME ?attributeName .
    _:0 fp:vALUE ?attributeValue .
}
}"""^^xsd:string ;
      sp:where (
          [
            rdf:type sp:NamedGraph ;
            sp:elements (
                [
                  sp:object [
                      sp:varName "?0"^^xsd:string ;
                    ] ;
                  sp:predicate <http://www.topbraid.org/2007/05/composite.owl#child> ;
                  sp:subject [
                      sp:varName "a1_mindmapNode"^^xsd:string ;
                    ] ;
                ]
                [
                  sp:object <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#Attribute> ;
                  sp:predicate rdf:type ;
                  sp:subject [
                      sp:varName "?0"^^xsd:string ;
                    ] ;
                ]
                [
                  sp:object [
                      sp:varName "attributeName"^^xsd:string ;
                    ] ;
                  sp:predicate <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#nAME> ;
                  sp:subject [
                      sp:varName "?0"^^xsd:string ;
                    ] ;
                ]
                [
                  sp:object [
                      sp:varName "attributeValue"^^xsd:string ;
                    ] ;
                  sp:predicate <http://onto.fel.cvut.cz/ontologies/xml-schema/freeplane_1.3.x#vALUE> ;
                  sp:subject [
                      sp:varName "?0"^^xsd:string ;
                    ] ;
                ]
              ) ;
            sp:graphNameNode <file:///inbas/extract/freeplane/main.xml> ;
          ]
        ) ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:a1_mindmapNode ;
      rdfs:comment "Mindmap node from which attribute value should be taken."^^xsd:string ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:attributeName ;
      spl:valueType xsd:string ;
      rdfs:comment "Attribute name associated with mindmap node."^^xsd:string ;
    ] ;
  spin:returnType xsd:string ;
  rdfs:comment "Retrieve attribute value of specified mindmapNode by attributeName."^^xsd:string ;
  rdfs:subClassOf task:MindmapFunctions ;
.
arg:a1_mindmapNode
  rdf:type rdf:Property ;
  rdfs:subPropertyOf sp:arg ;
.
arg:attributeName
  rdf:type rdf:Property ;
  rdfs:subPropertyOf sp:arg ;
.
