# baseURI: http://lakOutputs.org/testGeoScript
# imports: http://topbraid.org/sparqlmotionfunctions
# imports: http://topbraid.org/sparqlmotionlib-tb
# prefix: testGeoScript

@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 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 testGeoScript: <http://lakOutputs.org/testGeoScript#> .
@prefix ui: <http://uispin.org/ui#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://lakOutputs.org/testGeoScript>
  a owl:Ontology ;
  owl:imports <http://topbraid.org/sparqlmotionfunctions> ;
  owl:imports <http://topbraid.org/sparqlmotionlib-tb> ;
  owl:versionInfo "Created with TopBraid Composer" ;
.
testGeoScript:CreateSWPDocument_1
  a sml:CreateSWPDocument ;
  sm:next testGeoScript:ExportToXMLFile_1 ;
  sm:outputVariable "doc" ;
  sml:snippet true ;
  sml:view [
      a ui:setContext ;
      <http://uispin.org/let#rootTagLabel> "geograghy" ;
      ui:child [
          a ui:group ;
          <http://uispin.org/let#rootTagName> [
              sp:varName "rootTagLabel" ;
            ] ;
          ui:child [
              a ui:forEach ;
              ui:child [
                  a ui:CommentNode ;
                  ui:childIndex 0 ;
                  rdfs:comment """<ui:bind>
<ui:group let:attr=\"name = &quot;{= smf:escapeXML(?name) }&quot;\" let:topTag=\"item\">
<ui:group let:subTag=\"&lt;{= ?topTag } {= ?attr }&gt;&lt;/{= ?topTag }&gt;\">
<ui:setGlobalVar ui:name=\"subTags\"
                 ui:value=\"{= ui:globalVarValue(&quot;subTags&quot;) }{= ?subTag }\"/>
</ui:group>
</ui:group>
</ui:bind>""" ;
                ] ;
              ui:child [
                  a ui:bind ;
                  ui:child [
                      a ui:group ;
                      <http://uispin.org/let#attr> [
                          a ui:concat ;
                          sp:arg1 "name = \"" ;
                          sp:arg2 [
                              a smf:escapeXML ;
                              sp:arg1 [
                                  sp:varName "name" ;
                                ] ;
                            ] ;
                          sp:arg3 "\"" ;
                        ] ;
                      <http://uispin.org/let#tagName> "item" ;
                      ui:child [
                          a ui:forEach ;
                          ui:child [
                              a ui:group ;
                              <http://uispin.org/let#subTag> [
                                  a ui:concat ;
                                  sp:arg1 "<" ;
                                  sp:arg2 [
                                      sp:varName "tagName" ;
                                    ] ;
                                  sp:arg3 " " ;
                                  sp:arg4 [
                                      sp:varName "attr" ;
                                    ] ;
                                  sp:arg5 ">" ;
                                  sp:arg6 [
                                      sp:varName "childrenConceptsResult" ;
                                    ] ;
                                  sp:arg7 "</" ;
                                  sp:arg8 [
                                      sp:varName "tagName" ;
                                    ] ;
                                  sp:arg9 ">" ;
                                ] ;
                              ui:child [
                                  a ui:setGlobalVar ;
                                  ui:childIndex 0 ;
                                  ui:name "subTags" ;
                                  ui:value [
                                      a ui:concat ;
                                      sp:arg1 [
                                          a ui:globalVarValue ;
                                          ui:name "subTags" ;
                                        ] ;
                                      sp:arg2 [
                                          sp:varName "subTag" ;
                                        ] ;
                                    ] ;
                                ] ;
                              ui:childIndex 0 ;
                            ] ;
                          ui:childIndex 0 ;
                          ui:resultSet [
                              a sp:Select ;
                              sp:resultVariables (
                                  [
                                    sp:varName "childrenConceptsResult" ;
                                  ]
                                ) ;
                              sp:where (
                                  [
                                    a sp:Bind ;
                                    sp:expression [
                                        a testGeoScript:getChildren ;
                                        <http://spinrdf.org/arg#parent> [
                                            a sp:iri ;
                                            sp:arg1 [
                                                sp:varName "result" ;
                                              ] ;
                                          ] ;
                                      ] ;
                                    sp:variable [
                                        sp:varName "childrenConceptsResult" ;
                                      ] ;
                                  ]
                                ) ;
                            ] ;
                        ] ;
                      ui:childIndex 0 ;
                    ] ;
                  ui:childIndex 1 ;
                ] ;
              ui:childIndex 0 ;
              ui:resultSet [
                  a sp:Select ;
                  sp:distinct true ;
                  sp:resultVariables (
                      [
                        sp:varName "result" ;
                      ]
                      [
                        sp:varName "name" ;
                      ]
                    ) ;
                  sp:where (
                      [
                        a sp:Bind ;
                        sp:expression [
                            a ui:graphWithImports ;
                            sp:arg1 <urn:x-evn-master:geo> ;
                          ] ;
                        sp:variable [
                            sp:varName "graph" ;
                          ] ;
                      ]
                      [
                        a sp:NamedGraph ;
                        sp:elements (
                            [
                              a sp:TriplePath ;
                              sp:object <http://www.w3.org/2004/02/skos/core#Concept> ;
                              sp:path [
                                  a sp:ModPath ;
                                  sp:modMax -2 ;
                                  sp:modMin 0 ;
                                  sp:subPath rdfs:subClassOf ;
                                ] ;
                              sp:subject [
                                  sp:varName "type" ;
                                ] ;
                            ]
                            [
                              sp:object [
                                  sp:varName "type" ;
                                ] ;
                              sp:predicate rdf:type ;
                              sp:subject [
                                  sp:varName "result" ;
                                ] ;
                            ]
                            [
                              a sp:Filter ;
                              sp:expression [
                                  a sp:notExists ;
                                  sp:elements (
                                      [
                                        sp:object [
                                            sp:varName "parent" ;
                                          ] ;
                                        sp:predicate <http://www.w3.org/2004/02/skos/core#broader> ;
                                        sp:subject [
                                            sp:varName "result" ;
                                          ] ;
                                      ]
                                    ) ;
                                ] ;
                            ]
                            [
                              a sp:Optional ;
                              sp:elements (
                                  [
                                    sp:object [
                                        sp:varName "name" ;
                                      ] ;
                                    sp:predicate <http://www.w3.org/2004/02/skos/core#prefLabel> ;
                                    sp:subject [
                                        sp:varName "result" ;
                                      ] ;
                                  ]
                                  [
                                    a sp:Filter ;
                                    sp:expression [
                                        a sp:eq ;
                                        sp:arg1 [
                                            a sp:lang ;
                                            sp:arg1 [
                                                sp:varName "name" ;
                                              ] ;
                                          ] ;
                                        sp:arg2 "en" ;
                                      ] ;
                                  ]
                                ) ;
                            ]
                          ) ;
                        sp:graphNameNode [
                            sp:varName "graph" ;
                          ] ;
                      ]
                    ) ;
                ] ;
            ] ;
          ui:child [
              a ui:parse ;
              ui:childIndex 1 ;
              ui:str [
                  a ui:concat ;
                  sp:arg1 "<" ;
                  sp:arg2 [
                      sp:varName "rootTagName" ;
                    ] ;
                  sp:arg3 ">" ;
                  sp:arg4 [
                      a ui:globalVarValue ;
                      ui:name "subTags" ;
                    ] ;
                  sp:arg5 "</" ;
                  sp:arg6 [
                      sp:varName "rootTagName" ;
                    ] ;
                  sp:arg7 ">" ;
                ] ;
              ui:xml true ;
            ] ;
          ui:childIndex 1 ;
        ] ;
      ui:child [
          a ui:setGlobalVar ;
          ui:childIndex 0 ;
          ui:name "subTags" ;
          ui:value "" ;
        ] ;
    ] ;
  rdfs:label "Create SWPDocument 1" ;
.
testGeoScript:ExportToXMLFile_1
  a sml:ExportToXMLFile ;
  sml:targetFilePath "geoOutput.xml" ;
  sml:xml "{?doc}"^^rdf:XMLLiteral ;
  rdfs:label "Export to XMLFile 1" ;
.
testGeoScript:getChildren
  a ui:Function ;
  spin:constraint [
      a spl:Argument ;
      spl:predicate <http://spinrdf.org/arg#parent> ;
      spl:valueType rdfs:Resource ;
    ] ;
  ui:prototype [
      a ui:setContext ;
      ui:child [
          a ui:CommentNode ;
          ui:childIndex 2 ;
          rdfs:comment """<ui:group>
<ui:parse ui:str=\"{= ui:globalVarValue(&quot;subTags&quot;) }\" ui:xml=\"true\"/>
</ui:group>""" ;
        ] ;
      ui:child [
          a ui:forEach ;
          ui:child [
              a ui:CommentNode ;
              ui:childIndex 0 ;
              rdfs:comment """<ui:group let:attr=\"id =&quot;{= ?id }&quot; name = &quot;{= ?name }&quot;\" let:tagName=\"item\">
<ui:parse ui:str=\"&lt;{= ?tagName } {= ?attr }&gt;&lt;/{= ?tagName }&gt;\" ui:xml=\"true\"/>
</ui:group>""" ;
            ] ;
          ui:child [
              a ui:bind ;
              ui:child [
                  a ui:group ;
                  <http://uispin.org/let#attr> [
                      a ui:concat ;
                      sp:arg1 "name = \"" ;
                      sp:arg2 [
                          a smf:escapeXML ;
                          sp:arg1 [
                              sp:varName "name" ;
                            ] ;
                        ] ;
                      sp:arg3 "\"" ;
                    ] ;
                  <http://uispin.org/let#tagName> "item" ;
                  ui:child [
                      a ui:forEach ;
                      ui:child [
                          a ui:group ;
                          <http://uispin.org/let#subTag> [
                              a ui:concat ;
                              sp:arg1 "<" ;
                              sp:arg2 [
                                  sp:varName "tagName" ;
                                ] ;
                              sp:arg3 " " ;
                              sp:arg4 [
                                  sp:varName "attr" ;
                                ] ;
                              sp:arg5 ">" ;
                              sp:arg6 [
                                  sp:varName "childrenConceptsResult" ;
                                ] ;
                              sp:arg7 "</" ;
                              sp:arg8 [
                                  sp:varName "tagName" ;
                                ] ;
                              sp:arg9 ">" ;
                            ] ;
                          ui:child [
                              a ui:setGlobalVar ;
                              ui:childIndex 0 ;
                              ui:name "subTags" ;
                              ui:value [
                                  a ui:concat ;
                                  sp:arg1 [
                                      a ui:globalVarValue ;
                                      ui:name "subTags" ;
                                    ] ;
                                  sp:arg2 [
                                      sp:varName "subTag" ;
                                    ] ;
                                ] ;
                            ] ;
                          ui:childIndex 0 ;
                        ] ;
                      ui:childIndex 0 ;
                      ui:resultSet [
                          a sp:Select ;
                          sp:resultVariables (
                              [
                                sp:varName "childrenConceptsResult" ;
                              ]
                            ) ;
                          sp:where (
                              [
                                a sp:Bind ;
                                sp:expression [
                                    a testGeoScript:getChildren ;
                                    <http://spinrdf.org/arg#parent> [
                                        a sp:iri ;
                                        sp:arg1 [
                                            sp:varName "result" ;
                                          ] ;
                                      ] ;
                                  ] ;
                                sp:variable [
                                    sp:varName "childrenConceptsResult" ;
                                  ] ;
                              ]
                            ) ;
                        ] ;
                    ] ;
                  ui:childIndex 0 ;
                ] ;
              ui:childIndex 1 ;
            ] ;
          ui:childIndex 1 ;
          ui:resultSet [
              a sp:Select ;
              sp:distinct true ;
              sp:resultVariables (
                  [
                    sp:varName "result" ;
                  ]
                  [
                    sp:varName "name" ;
                  ]
                ) ;
              sp:where (
                  [
                    a sp:Bind ;
                    sp:expression [
                        a ui:graphWithImports ;
                        sp:arg1 <urn:x-evn-master:geo> ;
                      ] ;
                    sp:variable [
                        sp:varName "graph" ;
                      ] ;
                  ]
                  [
                    a sp:NamedGraph ;
                    sp:elements (
                        [
                          sp:object [
                              sp:varName "parent" ;
                            ] ;
                          sp:predicate <http://www.w3.org/2004/02/skos/core#broader> ;
                          sp:subject [
                              sp:varName "result" ;
                            ] ;
                        ]
                        [
                          a sp:Optional ;
                          sp:elements (
                              [
                                sp:object [
                                    sp:varName "name" ;
                                  ] ;
                                sp:predicate <http://www.w3.org/2004/02/skos/core#prefLabel> ;
                                sp:subject [
                                    sp:varName "result" ;
                                  ] ;
                              ]
                              [
                                a sp:Filter ;
                                sp:expression [
                                    a sp:eq ;
                                    sp:arg1 [
                                        a sp:lang ;
                                        sp:arg1 [
                                            sp:varName "name" ;
                                          ] ;
                                      ] ;
                                    sp:arg2 "en" ;
                                  ] ;
                              ]
                            ) ;
                        ]
                      ) ;
                    sp:graphNameNode [
                        sp:varName "graph" ;
                      ] ;
                  ]
                ) ;
            ] ;
        ] ;
      ui:child [
          a ui:return ;
          ui:childIndex 3 ;
          ui:result [
              a ui:globalVarValue ;
              ui:name "subTags" ;
            ] ;
        ] ;
      ui:child [
          a ui:setGlobalVar ;
          ui:childIndex 0 ;
          ui:name "subTags" ;
          ui:value "" ;
        ] ;
    ] ;
  rdfs:label "get children" ;
  rdfs:subClassOf ui:Functions ;
.
