|
|
# 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
|
|
|
|
|
|
```shell
|
|
|
# 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
|
|
|
|
|
|
|
|
|
```shell
|
|
|
# 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
|
|
|
|
|
|
![Package_unl](uploads/e8538df3289342e9cb32d0593eb6a7e3/Package_unl.png)
|
|
|
|
|
|
## Unl Graph creation
|
|
|
|
|
|
See source code [R1SentenceWithExpectedRdf.java](https://gitlab.tetras-libre.fr/unl/unl2rdf/-/blob/master/rdf/src/test/java/fr/tetras_libre/unltools/rdf/vocabulary/R1SentenceWithExpectedRdf.java)
|
|
|
|
|
|
# Some tricks
|
|
|
|
|
|
## Get the node for a GraphRelation with SubGraphReferenceNode
|
|
|
|
|
|
|
|
|
In order to respect [Law of Demeter](https://en.wikipedia.org/wiki/Law_of_Demeter) at the Graph level
|
|
|
|
|
|
```java
|
|
|
|
|
|
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. |