Salt  3.4.2
A powerful, tagset-independent and theory-neutral meta model and API for storing, manipulating, and representing nearly all types of linguistic data .
org.corpus_tools.salt.util.VisJsVisualizer Class Reference

Inherits org.corpus_tools.salt.core.GraphTraverseHandler.

Public Member Functions

 VisJsVisualizer (SDocument doc) throws IOException
 Creates a new VisJsVisualizer instance for specified salt document. More...
 
 VisJsVisualizer (SDocument doc, ExportFilter exportFilter, StyleImporter styleImporter) throws IOException
 Creates a new VisJsVisualizer instance with specified export filter for specified salt document. More...
 
 VisJsVisualizer (URI inputFileUri) throws IOException
 Creates a new VisJsVisualizer instance for a salt file specified by the uri. More...
 
 VisJsVisualizer (URI inputFileUri, ExportFilter exportFilter, StyleImporter styleImporter) throws IOException
 Creates a new VisJsVisualizer instance with specified export filter for a salt file specified by the uri. More...
 
void visualize (URI outputFolderUri) throws SaltParameterException, SaltResourceException, SaltException, SaltResourceException, IOException, XMLStreamException
 
void setNodeWriter (OutputStream os)
 Creates a new buffered writer with specified output stream. More...
 
void setEdgeWriter (OutputStream os)
 Creates a new buffered writer with specified output stream. More...
 
void buildJSON () throws SaltException, SaltParameterException
 By invoking of this method the graph of the salt document specified by the constructor will be traversed. More...
 
void nodeReached (GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order)
 Implements the nodeReached method of the org.corpus_tools.salt.core.GraphTraverseHandler interface.
 
void nodeLeft (GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation relation, SNode fromNode, long order)
 Implements the nodeLeft method of the org.corpus_tools.salt.core.GraphTraverseHandler interface.
 
boolean checkConstraint (GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SRelation relation, SNode currNode, long order)
 Implements the checkConstraint method of the org.corpus_tools.salt.core.GraphTraverseHandler interface.
 
- Public Member Functions inherited from org.corpus_tools.salt.core.GraphTraverseHandler
void nodeReached (GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation< SNode, SNode > relation, SNode fromNode, long order)
 This method will be invoked, when a node is reached, after the method checkConstraint(GRAPH_TRAVERSE_TYPE, String, SRelation, SNode, long) has returned true and before the method nodeLeft(GRAPH_TRAVERSE_TYPE, String, SNode, SRelation, SNode, long) is invoked. More...
 
void nodeLeft (GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode, SRelation< SNode, SNode > relation, SNode fromNode, long order)
 This method will be invoked, when a node is left, after the method checkConstraint(GRAPH_TRAVERSE_TYPE, String, SRelation, SNode, long) has returned true and the method nodeReached(GRAPH_TRAVERSE_TYPE, String, SNode, SRelation, SNode, long) has been invoked. More...
 
boolean checkConstraint (GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SRelation< SNode, SNode > relation, SNode currNode, long order)
 This method is called during a traversal to check if the current node and eventually its sub-graph shall be traversed or not. More...
 

Public Attributes

BufferedWriter nodeWriter
 
BufferedWriter edgeWriter
 

Static Public Attributes

static final String CSS_FOLDER_OUT = "css"
 
static final String IMG_FOLDER_OUT
 
static final String JS_FOLDER_OUT = "js"
 
static final String CSS_FILE = "vis.min.css"
 
static final String JS_FILE = "vis.min.js"
 
static final String JQUERY_FILE = "jquery.js"
 
static final String HTML_FILE = "saltVisJs.html"
 

Detailed Description

This class provides a possibility to create a html file, which visualizes a salt graph, created from an SDocument or from an org.eclipse.emf.common.util.URI of a salt file, using the vis.js library from visjs.org.

Also it can be used to get both nodes and relations of a salt document in JSON format. Note, if no export filter used, all nodes and all relations but textual relations will be visualized.

A simple way to use this class for writing the html file is shown in the following example code.

String inputSaltFile = "path_to_your_salt_file";
String outputFolder = "path_to_your_output_folder";
URI uri = URI.createFileURI(inputSaltFile);
VisJsVisualizer visJsVisualizer = new VisJsVisualizer(uri);
try {
URI outputFileUri = URI.createFileURI(outputFolder);
visJsVisualizer.visualize(outputFileUri);
} catch (IOException | XMLStreamException e) {
e.printStackTrace();
}

The next listing shows how to get the nodes and the relations of an input salt file in JSON format by use of this class. For simplicity, the created JSON objects will be written to the standard output.

URI uri = URI.createFileURI("path_to_the_input_salt_file");
OutputStream nodeStream = Sytem.out;
OutputStream edgeStream = System.out;
VisJsVisualizer.setNodeWriter(nodeStream);
VisJsVisualizer.setEdgeWriter(edgeStream);
VisJsVisualizer.buildJSON();
try {
nodeStream.write('\n'); nodeStream.flush();
edgeStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
Author
irina

Constructor & Destructor Documentation

◆ VisJsVisualizer() [1/4]

org.corpus_tools.salt.util.VisJsVisualizer.VisJsVisualizer ( SDocument  doc) throws IOException

Creates a new VisJsVisualizer instance for specified salt document.

Parameters
docan SDocument to be visualized
Exceptions
IOExceptionif creation of tmp file failed *
SaltParameterExceptionif the doc is null

◆ VisJsVisualizer() [2/4]

org.corpus_tools.salt.util.VisJsVisualizer.VisJsVisualizer ( SDocument  doc,
ExportFilter  exportFilter,
StyleImporter  styleImporter 
) throws IOException

Creates a new VisJsVisualizer instance with specified export filter for specified salt document.

Parameters
docan SDocument to be visualized
exportFilteran ExportFilter to include or exclude nodes and/or relations explicitly. If null, all nodes and relations will be visualized.
styleImportera StyleImporter to highlight nodes. If null, no nodes will be highlighted.
Exceptions
IOExceptionif creation of tmp file failed
SaltParameterExceptionif doc is null

◆ VisJsVisualizer() [3/4]

org.corpus_tools.salt.util.VisJsVisualizer.VisJsVisualizer ( URI  inputFileUri) throws IOException

Creates a new VisJsVisualizer instance for a salt file specified by the uri.

Parameters
inputFileUria hierarchical org.eclipse.emf.common.util.URI of a salt file to be visualized. The constructor will create a new SDocument of this.
Exceptions
IOExceptionif creation of tmp file failed
SaltParameterException
  • if the inputFileUri is null

◆ VisJsVisualizer() [4/4]

org.corpus_tools.salt.util.VisJsVisualizer.VisJsVisualizer ( URI  inputFileUri,
ExportFilter  exportFilter,
StyleImporter  styleImporter 
) throws IOException

Creates a new VisJsVisualizer instance with specified export filter for a salt file specified by the uri.

Parameters
inputFileUria hierarchical org.eclipse.emf.common.util.URI of a salt file, which has to be visualized. The constructor will create a new SDocument of this.
exportFilteran ExportFilter to include or exclude nodes and/or relations explicitly. If null, all nodes and relations will be visualized.
styleImportera StyleImporter to highlight nodes. If null, no nodes will be highlighted.
Exceptions
IOExceptionif creation of tmp file failed
SaltParameterExceptionif the inputFileUri is null
SaltResourceExceptionif a problem occurred while loading salt project from the inputFileUri

Member Function Documentation

◆ buildJSON()

void org.corpus_tools.salt.util.VisJsVisualizer.buildJSON ( ) throws SaltException, SaltParameterException

By invoking of this method the graph of the salt document specified by the constructor will be traversed.

Both the nodeWriter and the edgeWriter write nodes and relations of this graph respective to the associated output streams.

Exceptions
SaltExceptionif a problem occurred while building JSON objects
SaltParameterExceptionif the node writer and/or the edge writer not set

◆ setEdgeWriter()

void org.corpus_tools.salt.util.VisJsVisualizer.setEdgeWriter ( OutputStream  os)

Creates a new buffered writer with specified output stream.

It will contain the edges in JSON format after invoking of the buildJSON() method.

Parameters
osOutputStream associated to the edge writer

◆ setNodeWriter()

void org.corpus_tools.salt.util.VisJsVisualizer.setNodeWriter ( OutputStream  os)

Creates a new buffered writer with specified output stream.

It will contain the nodes in JSON format after invoking of the buildJSON() method.

Parameters
osOutputStream associated to the node writer.

◆ visualize()

void org.corpus_tools.salt.util.VisJsVisualizer.visualize ( URI  outputFolderUri) throws SaltParameterException, SaltResourceException, SaltException, SaltResourceException, IOException, XMLStreamException

This method writes the html document, which visualizes the Salt document, specified by constructor. The output folder structure will be created, if not yet exists. The output html file as well as the auxiliary files will be written.

The whole output structure will look like following:

Parameters
outputFolderUria hierarchical org.eclipse.emf.common.util.URI that specifies the output folder path. Note, that the output folder have not necessarily to be existing.
Exceptions
SaltParameterExceptionif the outputFolderUri is null
SaltResourceExceptionif the output auxiliary files cannot have been created
SaltExceptionif the output folders cannot have been created or permission denied
SaltResourceExceptionif a problem occurred while copying the auxiliary files
XMLStreamExceptionif a problem occurred while writing the output html file
IOExceptionif a problem occurred while writing the output file

Member Data Documentation

◆ IMG_FOLDER_OUT

final String org.corpus_tools.salt.util.VisJsVisualizer.IMG_FOLDER_OUT
static
Initial value:
= CSS_FOLDER_OUT + System.getProperty("file.separator") + "img"
+ System.getProperty("file.separator") + "network"
org.corpus_tools.salt.util.VisJsVisualizer.VisJsVisualizer
VisJsVisualizer(SDocument doc)
Creates a new VisJsVisualizer instance for specified salt document.
Definition: VisJsVisualizer.java:289