Unl tools
UnlTools is a set of tools about Unl document files. It provides :
- Parser of UNL Files;
- Exporter to Dot format and Turtle format;
- Programming api to create Unl graphs.
Usage
Generate dot file
# generate /tmp/bar.dot from foo.txt unl format text file
java -jar unl2rdf-jar-with-dependencies.jar --input-file foo.txt --output-file bar --output-type dot --output-dir /tmp
Generate turtle file
# generate /tmp/bar.ttl from foo.txt unl format text file
java -jar unl2rdf-jar-with-dependencies.jar --input-file foo.txt --output-file bar --output-type rdf --output-dir /tmp
Programming API
Class diagram
Unl Graph creation
See source code R1SentenceWithExpectedRdf.java
Some tricks
Get the node for a GraphRelation with SubGraphReferenceNode
In order to respect Law of Demeter at the Graph level
public class GraphExtensions {
public static GraphNode getRealNode1(Graph g, GraphRelation graphRelation) throws NoEntryNodeException {
return getRealNode(g, graphRelation.getNode1());
}
public static GraphNode getRealNode2(Graph g, GraphRelation graphRelation) throws NoEntryNodeException {
return getRealNode(g, graphRelation.getNode2());
}
private static GraphNode getRealNode(Graph g, GraphNode graphNode) throws NoEntryNodeException {
if (graphNode instanceof UniversalWordNode) {
return getRealNode(g, (UniversalWordNode)graphNode);
}
if(graphNode instanceof SubGraphReferenceNode) {
return getRealNode(g, (SubGraphReferenceNode)graphNode);
}
throw new IllegalArgumentException(String.format("Not implemented for '%s'", graphNode.getClass()));
}
private static GraphNode getRealNode(Graph g, UniversalWordNode universalWordNode){
return universalWordNode;
}
private static GraphNode getRealNode(Graph g, SubGraphReferenceNode graphNodeReference) throws NoEntryNodeException {
return g.getEntryNode(graphNodeReference.getReferenceNumber());
}
}
Be carefull a the level of GraphReation if one of the two nodes is SubGraphReferenceNode then the Corresponding NodeId is null within the node instead use the extension GraphExtensions.getRealNode(g, relationNode).getNodeId() to get the corresponding node id.