You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by afs <gi...@git.apache.org> on 2018/05/07 19:01:12 UTC
[GitHub] jena pull request #416: JENA-1545: ParserProfileWrapper and public checkTrup...
GitHub user afs opened a pull request:
https://github.com/apache/jena/pull/416
JENA-1545: ParserProfileWrapper and public checkTruple, checkQuad
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/afs/jena parserprofile-wrapper
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/jena/pull/416.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #416
----
commit 669392c75bf53f25918578f140b07c068c2566e8
Author: Andy Seaborne <an...@...>
Date: 2018-05-07T16:45:43Z
JENA-1545: ParserProfileWrapper and public checkTruple, checkQuad
----
---
[GitHub] jena pull request #416: JENA-1545: ParserProfileWrapper and public checkTrup...
Posted by ajs6f <gi...@git.apache.org>.
Github user ajs6f commented on a diff in the pull request:
https://github.com/apache/jena/pull/416#discussion_r186517509
--- Diff: jena-arq/src/main/java/org/apache/jena/riot/system/ParserProfile.java ---
@@ -49,6 +49,12 @@
/** Create a triple */
public Triple createTriple(Node subject, Node predicate, Node object, long line, long col);
+ /** Check a triple */
--- End diff --
Might be nice to include a Javadoc note declaring what to do for bad tuples. Presumably `throw` something, but is there a specific type to throw that would be best?
---
[GitHub] jena pull request #416: JENA-1545: ParserProfileWrapper
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/jena/pull/416
---
[GitHub] jena issue #416: JENA-1545: ParserProfileWrapper and public checkTruple, che...
Posted by afs <gi...@git.apache.org>.
Github user afs commented on the issue:
https://github.com/apache/jena/pull/416
Extensively revised : calling `checkTriple` inside `createTriple` doesn't delegate properly in the proxy pattern. Instead, and in the interests of simplicity, any `ParserProfile` exposes enough setup state to allow a proxy to provide an alternative `createTriple` operation:
This way provides the immediate need for PR #299 without limiting future possibilities for stream based checking (e.g. to have a checking policy passed to a ParserProfile) to include line and column numbers. It is inline with the current javadoc for `ParserProfile` which already says a `FactoryRDF` is used.
Example, to allow literals as subjects:
public static void main(String[] args) {
ParserProfile pp = RiotLib.profile(Lang.TTL, "http://base/");
ParserProfile pp2 = new ParserProfileWrapper(pp) {
@Override public Triple createTriple(Node subject, Node predicate, Node object, long line, long col) {
if ( subject == null || (!subject.isURI() && !subject.isBlank() && !subject.isLiteral()) ) {
getErrorHandler().error("Subject is not a URI, blank node or literal", line, col);
throw new RiotException("Bad subject: " + subject);
}
if ( predicate == null || (!predicate.isURI()) ) {
getErrorHandler().error("Predicate not a URI", line, col);
throw new RiotException("Bad predicate: " + predicate);
}
if ( object == null || (!object.isURI() && !object.isBlank() && !object.isLiteral()) ) {
getErrorHandler().error("Object is not a URI, blank node or literal", line, col);
throw new RiotException("Bad object: " + object);
}
getErrorHandler().warning("Create triple!", line, col);
return getFactorRDF().createTriple(subject, predicate, object);
}
};
// Example of literal subject, calling machinery directly.
Tokenizer t = TokenizerFactory.makeTokenizer(new StringReader("123 <p> <o>"));
LangTurtle parser = new LangTurtle(t, pp2, StreamRDFLib.writer(System.out));
parser.parse();
}
---