Skip to content

Commit

Permalink
fix(TermFactory): term() method accepts an Object instead of a String…
Browse files Browse the repository at this point in the history
… to avoid Polyglot API cast issues
  • Loading branch information
ashleycaselli committed May 23, 2024
1 parent c8a30fb commit a538416
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/topbraid/shacl/js/model/TermFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public JSBlankNode blankNode(String value) {


public JSLiteral literal(Object value, Object langOrDatatype) {
String stringVal = value.toString();
System.out.println("value: " + value.getClass() + " " + value);
String stringVal = value.toString();
if (value instanceof Number) {
stringVal = String.valueOf(value);
}
Expand All @@ -76,13 +77,13 @@ public void registerNamespace(String prefix, String namespace) {
}


public JSTerm term(String str) {
Node n;
public JSTerm term(Object obj) {
Node n;
try {
n = NodeFactoryExtra.parseNode(str, pm);
n = NodeFactoryExtra.parseNode(String.valueOf(obj), pm);
}
catch(Exception ex) {
throw new IllegalArgumentException("Cannot parse node \"" + str + "\"", ex);
throw new IllegalArgumentException("Cannot parse node \"" + obj + "\"", ex);
}
if(n.isURI()) {
return new JSNamedNode(n);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/topbraid/shacl/py/model/PyTermFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public void registerNamespace(String prefix, String namespace) {
pm.add(prefix, namespace);
}

public PyTerm term(String str) {
public PyTerm term(Object obj) {
Node n;
try {
n = NodeFactoryExtra.parseNode(str, pm);
n = NodeFactoryExtra.parseNode(String.valueOf(obj), pm);
} catch (Exception ex) {
throw new IllegalArgumentException("Cannot parse node \"" + str + "\"", ex);
throw new IllegalArgumentException("Cannot parse node \"" + obj + "\"", ex);
}
if (n.isURI()) {
return new PyNamedNode(n);
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/js/tests/rules/rectangle-rdfquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ function computeArea($this) {
return $data.query().
match($this, "ex:width", "?width").
match($this, "ex:height", "?height").
bind("?area", function(sol) { return T(sol.width.lex * sol.height.lex) }).
bind("?area", function(sol) { return T(sol.width.getLex() * sol.height.getLex()) }).
construct($this, "ex:area", "?area");
}

0 comments on commit a538416

Please sign in to comment.