Hi German,

see the attached example. The key is to define a new helper function which takes two arguments and has a SPARQLMotion script as its body.



The new function can then be inserted into any other SM script from the Functions section, as a lego block.

Using SPIN constructors would not have the desired effect because it would be at module-creation time, not at run-time (which is what I believe you want).

HTH
Holger


On 7/06/2016 21:25, german.pete...@gmail.com wrote:
Hi,

I would like to to specialize existing SM module, by binding some of its arguments. More concretely, i would like to create module my:ImportGoogleSpreadsheetCSV by extending module sml:ImportFileFromURL. my:ImportGoogleSpreadsheetCSV should have 2 additional parameters -- documentId and sheetId. This is my definition of the module :

my:ImportGoogleSpreadsheetCSV
  rdf:type sm:Module ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate sml:documentId ;
      spl:valueType xsd:string ;
      rdfs:comment "Document Id."^^xsd:string ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate sml:sheetId ;
      spl:valueType xsd:string ;
      rdfs:comment "Spreadsheet id."^^xsd:string ;
    ] ;
  spin:constructor [
      rdf:type sp:Construct ;
      sp:templates (
          [
            sp:object [
                sp:varName "url"^^xsd:string ;
              ] ;
            sp:predicate sml:url ;
            sp:subject spin:_this ;
          ]
        ) ;
      sp:text """CONSTRUCT {
   ?this sml:url ?url .
}
WHERE {
BIND(CONCAT(\"https://docs.google.com/spreadsheets/d/\";, ?documentId, \"/export?format=csv&gid=\", ?sheetId) as ?url)
}"""^^xsd:string ;
      sp:where (
          [
            rdf:type sp:Bind ;
            sp:expression [
                rdf:type sp:concat ;
                sp:arg1 "https://docs.google.com/spreadsheets/d/"; ;
                sp:arg2 [
                    sp:varName "documentId"^^xsd:string ;
                  ] ;
                sp:arg3 "/export?format=csv&gid=" ;
                sp:arg4 [
                    sp:varName "sheetId"^^xsd:string ;
                  ] ;
              ] ;
            sp:variable [
                sp:varName "url"^^xsd:string ;
              ] ;
          ]
        ) ;
    ] ;
  rdfs:label "Import CSV from Google Spreadsheet"^^xsd:string ;
  rdfs:subClassOf sml:ImportFileFromURL ;
.


Idea is to use CONCAT function to bind ?url in spin:constructor. However, It gives me error: "Operation failed: org.topbraid.spin.sparqlmotion.modules.SMException: the string value is missing for url". This is clearly because sml:ImportFileFromURL module has "sml:url" argument which is required.

It there any way to disable required argument ? Is it correct way to do it ? Are there any other options to do it ?

Cheers,
Peter


--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include the TopBraid Suite family of products and its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to topbraid-users@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-users+unsubscr...@googlegroups.com <mailto:topbraid-users+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Group "TopBraid 
Suite Users", the topics of which include the TopBraid Suite family of products and 
its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to topbraid-users@googlegroups.com
--- You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to topbraid-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
# baseURI: http://example.org/sm/GoogleSpreadsheetCSV
# imports: http://topbraid.org/sparqlmotionfunctions
# imports: http://topbraid.org/sparqlmotionlib-tbc
# prefix: gocsv

@prefix arg: <http://spinrdf.org/arg#> .
@prefix gocsv: <http://example.org/sm/GoogleSpreadsheetCSV#> .
@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 sml: <http://topbraid.org/sparqlmotionlib#> .
@prefix sp: <http://spinrdf.org/sp#> .
@prefix spin: <http://spinrdf.org/spin#> .
@prefix spl: <http://spinrdf.org/spl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/sm/GoogleSpreadsheetCSV>
  rdf:type owl:Ontology ;
  owl:imports <http://topbraid.org/sparqlmotionfunctions> ;
  owl:imports <http://topbraid.org/sparqlmotionlib-tbc> ;
  owl:versionInfo "Created with TopBraid Composer" ;
.
gocsv:ImportFileFromURL_1
  rdf:type sml:ImportTextFromURL ;
  sm:next gocsv:ImportGoogleSpreadsheet_Return ;
  sm:outputVariable "result" ;
  sml:url 
"https://docs.google.com/spreadsheets/d/{?documentId}//export?format=csv&gid={?sheetId}";
 ;
  rdfs:label "Import file from URL 1" ;
.
gocsv:ImportGoogleSpreadsheet
  rdf:type sm:Function ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:documentId ;
      spl:valueType xsd:string ;
      sm:next gocsv:ImportFileFromURL_1 ;
    ] ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:sheetId ;
      spl:valueType xsd:string ;
      sm:next gocsv:ImportFileFromURL_1 ;
    ] ;
  sm:returnModule gocsv:ImportGoogleSpreadsheet_Return ;
  rdfs:subClassOf sm:Functions ;
.
gocsv:ImportGoogleSpreadsheetTest
  rdf:type gocsv:ImportGoogleSpreadsheet ;
  arg:documentId "MyDoc" ;
  arg:sheetId "42" ;
  sm:outputVariable "result" ;
  rdfs:label "Import google spreadsheet test" ;
.
gocsv:ImportGoogleSpreadsheet_Return
  rdf:type sml:ReturnNode ;
  sm:nodeX 293 ;
  sm:nodeY 268 ;
  sml:result [
      sp:varName "result" ;
    ] ;
.
arg:documentId
  rdf:type rdf:Property ;
  rdfs:subPropertyOf sp:arg ;
.
arg:sheetId
  rdf:type rdf:Property ;
  rdfs:subPropertyOf sp:arg ;
.

Reply via email to