problem with a function in a javascript file

37 views
Skip to first unread message

Pierluigi Ritrovato

unread,
Jan 14, 2015, 1:13:25 PM1/14/15
to topbrai...@googlegroups.com
I have defined a spin function that make some simple computation through a javascript snippet and works well.
Now I moved the snipped code in a js file and it doesn't work!

this is the spin function

tracking:isSmallDiff  a       spin:Function ;
        rdfs:label            "computes if difference is small"^^xsd:string ;
        rdfs:subClassOf       spin:Functions ;
        spin:constraint       [ a              spl:Argument ;
                                spl:predicate  sp:arg3 ;
                                spl:valueType  xsd:integer
                              ] ;
        spin:constraint       [ a              spl:Argument ;
                                spl:predicate  sp:arg2 ;
                                spl:valueType  xsd:integer
                              ] ;
        spin:constraint       [ a              spl:Argument ;
                                spl:predicate  sp:arg1 ;
                                spl:valueType  xsd:integer
                              ] ;
        spin:returnType       xsd:integer ;
        spinx:javaScriptFile  "isSmallDiff.js"^^xsd:string .
 
the js code is:

function isSmallDiff(arg1, arg2, arg3) {
if (Math.abs(arg1-arg2) < arg3) 
return 1; 
else 
return 0;
}

I copied the JS file any pace in my file system!

thank you very much in advance for any help.

Pierluigi

PS curiosity: the javascript code works only if I use arg1, arg2, .... arg5 as argument variables? 

Scott Henninger

unread,
Jan 14, 2015, 3:08:07 PM1/14/15
to topbrai...@googlegroups.com
Pierluigi; Is the file defined in the same folder as the file with the SPIN function?  It does need to be in the TopBraid workspace, and you can provide a relative or full path name for the js file.  Paths start with "/" in the root folder of the workspace, for example /TopBraid/common/foaf.ttl

-- Scott
--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), Reference Data Manager (RDM), TopBraid Composer, TopBraid Live, TopBraid Insight, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to topbrai...@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-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pierluigi Ritrovato

unread,
Jan 15, 2015, 3:44:30 AM1/15/15
to topbrai...@googlegroups.com
Scott thanks for reply.
The JS file is in the same dir of the spin rule file in the TB workspace (C:\Users\Pierluigi\TBCFreeWorkspace\MIVIA Tracking).
I'm testing the function with a simple query like this:

SELECT ?x
WHERE {
    LET (?x := tracking:isSmallDiff (2,2,3)) .
}

I'm using Top Braid Composer Free Edition 4.5.0 on Windows 8.1.

Scott Henninger

unread,
Jan 15, 2015, 4:20:15 PM1/15/15
to topbrai...@googlegroups.com
Pierluigi; Attached are two files that I've verified work with the example you've provided in TBC-Free.  Perhaps there is some detail that is different in your files.

Just as information, the W3C version of LET is BIND, i.e.:
  BIND(tracking:isSmallDiff (2,2,3) AS ?x)

-- Scott
tracking.spin.ttl
isSmallDiff.js

Pierluigi Ritrovato

unread,
Jan 19, 2015, 5:14:20 AM1/19/15
to topbrai...@googlegroups.com
Scott: Now I see. it is a matter on namespace. 
For a mistake in my rule file the base URI was an older one!

thanks again

Pierluigi


Il giorno mercoledì 14 gennaio 2015 19:13:25 UTC+1, Pierluigi Ritrovato ha scritto:
Reply all
Reply to author
Forward
0 new messages