Hi Michael,

in order to debug this best, could you send me all relevant files in the same set up as you have them? (Off-list). I would otherwise need to speculate and we'll have multiple back-and-forth emails.

In any case, the value spinx:math.js doesn't look like a correct file name. And you may want to try setting spinx:javaScriptCode instead of relying on the same-local-name policy. Defining the functions through some factory is going to complicate the situation, so better call them directly.

Reference: http://spinrdf.org/spinx.html

FWIW, from 5.4 onwards I'll recommend switching to SHACL-JS for user-defined functions.

Holger


On 30/08/2017 1:40, Michael Johnson wrote:
All,
I am trying to call the sqrt() function from the math.js library.
I have successfully created my own .js files and called functions with those, however calling functions from math.js seems to be a bit different

The math.js file is in my workspace.

I have created different subclasses to spin:Functions called:
ex:math.sqrt
ex:sqrt
ex:_sqrtNumber


For example, in my ontology is the definition for sqrt:
ex:sqrt
  rdf:type spin:Function ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate sp:arg1 ;
      spl:valueType rdfs:Literal ;
      rdfs:comment "The number to compute the square root of." ;
    ] ;
  spin:returnType xsd:float ;
<http://spinrdf.org/spinx#javaScriptFile> "spinx:math.js" ;
  rdfs:subClassOf spin:Functions ;
.


I am trying to do a bind in my sparql - none of which work....
BIND (ex:math.sqrt(10) as ?root ).
BIND (ex:_sqrtNumber (9) as ?sqrt) .
BIND (ex:sqrt(9) as ?sqrt2) .

The actual function in the math.js file  looks something like this:

function factory (type, config, load, typed) {
  /**
   * Calculate the square root of a value.
   *
   * For matrices, the function is evaluated element wise.
   *
   * Syntax:
   *
   *    math.sqrt(x)
   *
   * Examples:
   *
   *  math.sqrt(25);                // returns 5
   *  math.square(5);               // returns 25
   *  math.sqrt(-4);                // returns Complex 2i
   *
   * See also:
   *
   *    square, multiply, cube, cbrt
   *
   * @param {number | BigNumber | Complex | Array | Matrix | Unit} x
   *            Value for which to calculate the square root.
   * @return {number | BigNumber | Complex | Array | Matrix | Unit}
   *  Returns the square root of `x`
   */
  var sqrt = typed('sqrt', {
    'number': _sqrtNumber,

    'Complex': function (x) {
        return x.sqrt();
    },

With a private function below:

/**
   * Calculate sqrt for a number
   * @param {number} x
   * @returns {number | Complex} Returns the square root of x
   * @private
   */
  function _sqrtNumber(x) {
    if (x >= 0 || config.predictable) {
      return Math.sqrt(x);
    }
    else {
      return new type.Complex(x, 0).sqrt();
    }
  }

How can I successfully call the sqrt() function?
I hope to be able to do the same with additional functions.

Thanks,
Michael


--
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 [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to