swpExamples.ttl 11.1 KB
# baseURI: http://uispin.org/examples/swpExamples
# imports: http://topbraid.org/countries
# imports: http://uispin.org/uix

@prefix arg:     <http://spinrdf.org/arg#> .
@prefix ex:      <http://uispin.org/examples/swpExamples#> .
@prefix fn:      <http://www.w3.org/2005/xpath-functions#> .
@prefix html:    <http://uispin.org/html#> .
@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 ui:      <http://uispin.org/ui#> .
@prefix uix:     <http://uispin.org/uix#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .

arg:letter
      rdf:type rdf:Property ;
      rdfs:label "letter"^^xsd:string ;
      rdfs:subPropertyOf sp:arg .

<http://uispin.org/examples/swpExamples>
      rdf:type owl:Ontology ;
      owl:imports <http://topbraid.org/countries> , <http://uispin.org/uix> ;
      owl:versionInfo "Created with TopBraid Composer"^^xsd:string .

ex:ExpressionExample1
      rdf:type uix:Example ;
      rdfs:comment "Any SPARQL expression can be embedded into an SWP document wrapped by {= ... }"^^xsd:string ;
      rdfs:label "The {= ... } Notation: SPARQL Expressions"^^xsd:string ;
      rdfs:subClassOf ex:ExpressionExamples ;
      ui:prototype
              [ rdf:type html:Div ;
                ui:child
                        [ rdf:type ui:TextNode ;
                          ui:childIndex 0 ;
                          ui:text "The answer is "^^xsd:string
                        ] ;
                ui:child
                        [ rdf:type ui:TextNode ;
                          ui:childIndex 1 ;
                          ui:text [ rdf:type sp:add ;
                                    sp:arg1 20 ;
                                    sp:arg2 22
                                  ]
                        ]
              ] ;
      uix:level 1 ;
      uix:queryGraph <http://topbraid.org/countries> .

ex:ExpressionExamples
      rdf:type uix:Example ;
      rdfs:label "Expression examples"^^xsd:string ;
      rdfs:subClassOf uix:Examples ;
      uix:level 1 .

ex:ForEachExample1
      rdf:type uix:Example ;
      rdfs:label "Iterating: ui:forEach"^^xsd:string ;
      rdfs:subClassOf ex:ResultSetExamples ;
      ui:prototype
              [ rdf:type html:Div ;
                ui:child
                        [ rdf:type html:H3 ;
                          ui:child
                                  [ rdf:type ui:TextNode ;
                                    ui:childIndex 0 ;
                                    ui:text "Countries of the World"^^xsd:string
                                  ] ;
                          ui:childIndex 0
                        ] ;
                ui:child
                        [ rdf:type html:Ul ;
                          ui:child
                                  [ rdf:type ui:forEach ;
                                    ui:child
                                            [ rdf:type html:Li ;
                                              ui:child
                                                      [ rdf:type ui:TextNode ;
                                                        ui:childIndex 0 ;
                                                        ui:text [ sp:varName "label"^^xsd:string
                                                                ]
                                                      ] ;
                                              ui:childIndex 0
                                            ] ;
                                    ui:childIndex 0 ;
                                    ui:resultSet
                                            [ rdf:type sp:Select ;
                                              sp:orderBy ([ sp:varName "label"^^xsd:string
                                                        ]) ;
                                              sp:resultVariables ([ sp:expression
                                                                  [ rdf:type ui:label ;
                                                                    sp:arg1 [ sp:varName "country"^^xsd:string
                                                                            ]
                                                                  ] ;
                                                          sp:varName "label"^^xsd:string
                                                        ]) ;
                                              sp:where ([ sp:object <http://topbraid.org/countries#Country> ;
                                                          sp:predicate rdf:type ;
                                                          sp:subject
                                                                  [ sp:varName "country"^^xsd:string
                                                                  ]
                                                        ])
                                            ]
                                  ] ;
                          ui:childIndex 1
                        ]
              ] ;
      uix:level 2 ;
      uix:queryGraph <http://topbraid.org/countries> .

ex:FunctionCallExample1
      rdf:type uix:Example ;
      rdfs:comment "To insert the result of a SPARQL function call, use the {= ... } notation."^^xsd:string ;
      rdfs:label "The {= ... } Notation: Function calls"^^xsd:string ;
      rdfs:subClassOf ex:ExpressionExamples ;
      ui:prototype
              [ rdf:type html:Div ;
                ui:child
                        [ rdf:type ui:TextNode ;
                          ui:childIndex 0 ;
                          ui:text "Country code: "^^xsd:string
                        ] ;
                ui:child
                        [ rdf:type ui:TextNode ;
                          ui:childIndex 1 ;
                          ui:text [ rdf:type spl:object ;
                                    sp:arg1 <http://topbraid.org/countries#DE> ;
                                    sp:arg2 <http://topbraid.org/countries#abbreviation>
                                  ]
                        ]
              ] ;
      uix:level 4 ;
      uix:queryGraph <http://topbraid.org/countries> .

ex:GetSortedCountriesStartingWithLetter
      rdf:type spin:SelectTemplate ;
      rdfs:label "Get sorted countries starting with letter"^^xsd:string ;
      rdfs:subClassOf spin:SelectTemplates ;
      spin:body
              [ rdf:type sp:Select ;
                sp:orderBy ([ sp:varName "label"^^xsd:string
                          ]) ;
                sp:resultVariables ([ sp:varName "label"^^xsd:string
                          ]) ;
                sp:where ([ sp:object <http://topbraid.org/countries#Country> ;
                            sp:predicate rdf:type ;
                            sp:subject
                                    [ sp:varName "country"^^xsd:string
                                    ]
                          ] [ rdf:type sp:Bind ;
                            sp:expression
                                    [ rdf:type ui:label ;
                                      sp:arg1 [ sp:varName "country"^^xsd:string
                                              ]
                                    ] ;
                            sp:variable
                                    [ sp:varName "label"^^xsd:string
                                    ]
                          ] [ rdf:type sp:Filter ;
                            sp:expression
                                    [ rdf:type fn:starts-with ;
                                      sp:arg1 [ rdf:type fn:lower-case ;
                                                sp:arg1 [ sp:varName "label"^^xsd:string
                                                        ]
                                              ] ;
                                      sp:arg2 [ rdf:type fn:lower-case ;
                                                sp:arg1 [ sp:varName "letter"^^xsd:string
                                                        ]
                                              ]
                                    ]
                          ])
              ] ;
      spin:constraint
              [ rdf:type spl:Argument ;
                rdfs:comment "The letter the country has to start with."^^xsd:string ;
                spl:predicate arg:letter ;
                spl:valueType xsd:string
              ] .

ex:ResultSetExamples
      rdf:type uix:Example ;
      rdfs:label "Result set examples"^^xsd:string ;
      rdfs:subClassOf uix:Examples ;
      uix:level 2 .

ex:TemplateCallExample
      rdf:type uix:Example ;
      rdfs:comment "Reusable queries can be stored in SPIN templates. ui:call is used to execute those templates with the provided arguments. The result is a result set (by default called ?rs) that can be processed in the children of the ui:call element."^^xsd:string ;
      rdfs:label "Template call example"^^xsd:string ;
      rdfs:subClassOf ex:ResultSetExamples ;
      ui:prototype
              [ rdf:type html:Div ;
                ui:child
                        [ rdf:type html:H3 ;
                          ui:child
                                  [ rdf:type ui:TextNode ;
                                    ui:childIndex 0 ;
                                    ui:text "Countries starting with A"^^xsd:string
                                  ] ;
                          ui:childIndex 0
                        ] ;
                ui:child
                        [ rdf:type html:Ul ;
                          ui:child
                                  [ rdf:type ui:call ;
                                    arg:letter "a"^^xsd:string ;
                                    ui:child
                                            [ rdf:type ui:forEach ;
                                              ui:child
                                                      [ rdf:type html:Li ;
                                                        ui:child
                                                                [ rdf:type ui:TextNode ;
                                                                  ui:childIndex 0 ;
                                                                  ui:text [ sp:varName "label"^^xsd:string
                                                                          ]
                                                                ] ;
                                                        ui:childIndex 0
                                                      ] ;
                                              ui:childIndex 0 ;
                                              ui:resultSet
                                                      [ sp:varName "rs"^^xsd:string
                                                      ]
                                            ] ;
                                    ui:childIndex 0 ;
                                    ui:template ex:GetSortedCountriesStartingWithLetter
                                  ] ;
                          ui:childIndex 1
                        ]
              ] ;
      uix:level 3 ;
      uix:queryGraph <http://uispin.org/examples/swpExamples> .