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.SaltUtil Class Reference

This class contains a set of helpful methods. More...

Static Public Member Functions

static String createQName (String namespace, String name)
 Returns the concatenation of a labels namespace and a labels name as a qualified name: qname= NAMESPACE {@value NAMESPACE_SEPERATOR} NAME. More...
 
static Pair< String, String > splitQName (String qName)
 Splits the passed qName into a namespace and a name. More...
 
static URI createSaltURI (URI path)
 When specified corpus path already contains salt schema, then specified corpus path is returned. More...
 
static URI createSaltURI (String path)
 When specified corpus path already contains salt schema, then specified corpus path is returned. More...
 
static String getGlobalId (Identifier id)
 Returns a global ID for the passed object (either if Identifier belongs to SDocument or SCorpus object). More...
 
static Object load (URI location)
 Loads an object coming from a SaltXML (. More...
 
static List< Object > loadObjects (URI location)
 Loads a list of root objects coming from a SaltXML (. More...
 
static void moveCorpusGraph (SCorpusGraph source, SCorpusGraph target)
 Moves the content of source to target. More...
 
static void saveDocumentGraph (SDocumentGraph documentGraph, URI location)
 Persists the passed SDocumentGraph object in a SaltXML file at the passed location. More...
 
static SDocumentGraph loadDocumentGraph (URI location)
 Loads a SDocumentGraph object and returns it. More...
 
static void saveCorpusGraph (SCorpusGraph corpusGraph, URI location)
 Persists the passed SCorpusGraph object in a {@value SaltUtil::FILE_ENDING_SALT_XML} file at the passed location. More...
 
static SCorpusGraph loadCorpusGraph (URI corpusPath)
 Loads the given SaltXML file (. More...
 
static SCorpusGraph loadCorpusGraph (URI corpusPath, Integer idxOfSCorpusGraph)
 Loads the given SaltXML file (. More...
 
static void saveSaltProject (SaltProject saltProject, URI location)
 Persists the passed SaltProject object in a SaltXML file at the passed location. More...
 
static SaltProject loadCompleteSaltProject (URI location)
 Loads a SaltProject from given uri and returns it as object structure. More...
 
static SaltProject loadSaltProject (URI location)
 Loads a SaltProject from given uri and returns it as object structure. More...
 
static void saveCorpusGraph_DOT (SCorpusGraph corpusGraph, URI location)
 Stores a SCorpusGraph into DOT file. More...
 
static void saveDocumentGraph_DOT (SDocumentGraph documentGraph, URI location)
 Stores a SDocumentGraph into DOT file. More...
 
static void save_DOT (Object saltObject, URI location)
 This method stores a Salt model in the dot syntax (see: http://www.graphviz.org/) in a file. More...
 
static< P extends Label > P getAnnotation (Integer idx, Set< P > annotations)
 Returns the annotation at position idx in the passed set of annotations. More...
 
static void moveAnnotations (SAnnotationContainer from, SAnnotationContainer to)
 Moves all SAnnotation objects from from to to. More...
 
static void moveMetaAnnotations (SAnnotationContainer from, SAnnotationContainer to)
 Moves all SMetaAnnotation objects from from to to. More...
 
static Collection< String[]> unmarshalAnnotation (String marshalledString)
 Splits an annotation string of the form 'namespace::name=value (,namespace::name=value)* into a collection of (namespace, name, value). More...
 
static< S extends Object > Builder< S > compare (S saltElement)
 Creates a builder to have a fluent api for comparing two SDocumentGraphs or SCorpusGraphs. More...
 
static< T > boolean isNullOrEmpty (final Collection< T > collection)
 Checks whether a collection is null or empty. More...
 
static< T > boolean isNotNullOrEmpty (final Collection< T > collection)
 Checks whether a collection is not null nor empty. More...
 
static boolean belongsToCorpusStructure (final Object element)
 Returns whether specified Salt element is part of the corpus structure. More...
 
static< T extends Object > Validator.Builder< T > validate (T saltObject)
 Validates a salt project, a document structure or a corpus structure. More...
 

Static Public Attributes

static final String SALT_SCHEME = "salt"
 The URI scheme for corpus pathes.
 
static final String FILE_ENDING_SALT_XML = "salt"
 The ending of a Salt XML file.
 
static final String FILE_ENDING_DOT = "dot"
 The ending of a dot file.
 
static final String FILE_SALT_PROJECT = "saltProject" + "." + FILE_ENDING_SALT_XML
 Default name of the saltProject file.
 
static final String SALT_NAMESPACE = "salt"
 default name for of derived namespace-attribute
 
static final String NAMESPACE_SEPERATOR = "::"
 Separator between namespace and name: qname= NAMESPACE {@value NAMESPACE_SEPERATOR} NAME.
 
static final String SALT_NULL_VALUE = SaltUtil.SALT_NAMESPACE + SaltUtil.NAMESPACE_SEPERATOR + "NULL"
 A NULL value as String.
 
static final String IDX_NODETYPE = "idx_sNodeType"
 name of index for node-types
 
static final String IDX_RELATIONTYPE = "idx_sRelationType"
 name of index for relation-types
 
static final String IDX_ID_NODES = "idx_id_nodes"
 name of index for relating ids and nodes
 
static final String IDX_ID_NODES_INVERSE = "idx_id_nodes_inverse"
 name of index for relating ids and nodes (inverse)
 
static final String IDX_ID_RELATIONS = "idx_id_relation"
 name of index for relating ids and relations
 
static final String IDX_ID_RELATIONS_INVERSE = "idx_id_relation_inverse"
 name of index for relating ids and relations (inverse)
 
static final String IDX_ID_LAYER = "idx_id_layer"
 name of index for relating ids and layers
 
static final String IDX_OUT_RELATIONS = "idx_out_relations"
 name of index for relating node ids and outgoing relations
 
static final String IDX_IN_RELATIONS = "idx_in_relations"
 name of index for relating node ids and incoming relations
 
static final String LABEL_ID = "id"
 Name of Label to store the identifier of a node, relation, graph or layer.
 
static final String LABEL_ID_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + LABEL_ID
 Qualified name of Label to store the identifier of a node, relation, graph or layer.
 
static final String FEAT_VALUE_DATATYPE = "SVAL_TYPE"
 Name for SFeature to store the type of a labels value.
 
static final String FEAT_NAME = "SNAME"
 Name for SFeature to store the name of a node, relation, graph or label.
 
static final String FEAT_NAME_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + FEAT_NAME
 Qualified name for SFeature to store the name of a node, relation, graph or label.
 
static final String FEAT_TYPE = "STYPE"
 Name for SFeature to store the type of a relation.
 
static final String FEAT_TYPE_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + FEAT_TYPE
 Qualified name for SFeature to store the type of a relation.
 
static final String FEAT_SDOCUMENT_GRAPH = "SDOCUMENT_GRAPH"
 Name for SFeature to store the SDocumentGraph in a SDocument object.
 
static final String FEAT_SDOCUMENT_GRAPH_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + "SDOCUMENT_GRAPH"
 Qualified name for SFeature to store the SDocumentGraph in a SDocument object.
 
static final String FEAT_SDOCUMENT = "SDOCUMENT"
 Name for SFeature to store the SDocument corresponding to a SDocumentGraph object.
 
static final String FEAT_SDOCUMENT_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + "SDOCUMENT"
 Qualified name for SFeature to store the SDocument corresponding to a SDocumentGraph object.
 
static final String FEAT_SDOCUMENT_GRAPH_LOCATION = "SDOCUMENT_GRAPH_LOCATION"
 Name for SFeature to store the uri reference of a SDocumentGraph in a SDocument.
 
static final String FEAT_SDOCUMENT_GRAPH_LOCATION_QNAME
 Qualified name name for SFeature to store the uri reference of a SDocumentGraph in a SDocument. More...
 
static final String FEAT_SMEDIA_REFERNCE = "SAUDIO_REFERENCE"
 The name of the SFeature for the reference to an audio file.
 
static final String FEAT_SMEDIA_REFERNCE_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + FEAT_SMEDIA_REFERNCE
 The qualified name of the name of the SFeature for the reference to an audio file.
 
static final String FEAT_SSTART = "SSTART"
 The name of the SFeature for the start value.
 
static final String FEAT_SSTART_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + FEAT_SSTART
 The qualified name of the name of the SFeature for the start value.
 
static final String FEAT_SEND = "SEND"
 The name of the SFeature for the end value.
 
static final String FEAT_SEND_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + FEAT_SEND
 The qualified name of the name of the SFeature for the end value.
 
static final String FEAT_SDATA = "SDATA"
 The name of the SFeature for the data label for textual sources, etc. More...
 
static final String FEAT_SDATA_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + FEAT_SDATA
 Qualified name name of the SFeature for the data label for textual sources, etc. More...
 
static final String SEMANTICS_CAT = "cat"
 name for SCatAnnotation
 
static final String SEMANTICS_POS = "pos"
 name for SPOSAnnotation
 
static final String SEMANTICS_LEMMA = "lemma"
 name for SLemmaAnnotation
 
static final String SEMANTICS_SENTENCE = "sentence"
 name for SSentenceAnnotation
 
static final String SEMANTICS_TYPE = "type"
 value for STypeAnnotation
 
static final String SEMANTICS_WORD = "word"
 value for SWordAnnotation
 
static final String SEMANTICS_UNIT = "unit"
 name for SWordAnnotation and SSentenceAnnotation
 

Detailed Description

This class contains a set of helpful methods.

Author
florian

Member Function Documentation

◆ belongsToCorpusStructure()

static boolean org.corpus_tools.salt.util.SaltUtil.belongsToCorpusStructure ( final Object  element)
static

Returns whether specified Salt element is part of the corpus structure.

Parameters
elementSalt element
Returns
true, when Salt element is a part of the corpus structure, false otherwise

◆ compare()

static <S extends Object> Builder<S> org.corpus_tools.salt.util.SaltUtil.compare ( saltElement)
static

Creates a builder to have a fluent api for comparing two SDocumentGraphs or SCorpusGraphs.

compare(graph1).with(graph2).useOption(key, value).andCheckIsomorphie().
or
compare(graph1).with(graph2).useOption(key, value).andFindDiffs().

◆ createQName()

static String org.corpus_tools.salt.util.SaltUtil.createQName ( String  namespace,
String  name 
)
static

Returns the concatenation of a labels namespace and a labels name as a qualified name: qname= NAMESPACE {@value NAMESPACE_SEPERATOR} NAME.

Parameters
namespacethe namespace of a label
namethe name of a label

◆ createSaltURI() [1/2]

static URI org.corpus_tools.salt.util.SaltUtil.createSaltURI ( String  path)
static

When specified corpus path already contains salt schema, then specified corpus path is returned.

Otherwise a absolute new corpus path which is equal to specified corpus path is returned, which is augmented for salt scheme. When specified corpusPath is null, null is returned.

Parameters
pathpath to an element
Returns
corresponding Salt URI

◆ createSaltURI() [2/2]

static URI org.corpus_tools.salt.util.SaltUtil.createSaltURI ( URI  path)
static

When specified corpus path already contains salt schema, then specified corpus path is returned.

Otherwise a absolute new corpus path which is equal to specified corpus path is returned, which is augmented for salt scheme. When specified corpusPath is null, null is returned.

Parameters
path
Returns

◆ getAnnotation()

static <P extends Label> P org.corpus_tools.salt.util.SaltUtil.getAnnotation ( Integer  idx,
Set< P >  annotations 
)
static

Returns the annotation at position idx in the passed set of annotations.

Parameters
idxposition of the annotation to be returned
annotationsset of annotations
Returns
annotation at position idx

◆ getGlobalId()

static String org.corpus_tools.salt.util.SaltUtil.getGlobalId ( Identifier  id)
static

Returns a global ID for the passed object (either if Identifier belongs to SDocument or SCorpus object).

A global id only can be returned, if the element is contained in a SCorpusGraph object.

Parameters
idObject to retrieve global id.
Returns
String value for global id, if one is given.

◆ isNotNullOrEmpty()

static <T> boolean org.corpus_tools.salt.util.SaltUtil.isNotNullOrEmpty ( final Collection< T >  collection)
static

Checks whether a collection is not null nor empty.

Parameters
list
Returns

◆ isNullOrEmpty()

static <T> boolean org.corpus_tools.salt.util.SaltUtil.isNullOrEmpty ( final Collection< T >  collection)
static

Checks whether a collection is null or empty.

Parameters
list
Returns

◆ load()

static Object org.corpus_tools.salt.util.SaltUtil.load ( URI  location)
static

Loads an object coming from a SaltXML (.

FILE_ENDING_SALT_XML) and returns it.

If multiple objects are contained in the file it will only load the first one.

Parameters
locationURI to SaltXML file containing the object or
null
if the fule does not contain any objects.
Returns
loaded object
See also
loadObjects(org.eclipse.emf.common.util.URI) loadObjects(...): similar function that returns all the objects of a file.

◆ loadCompleteSaltProject()

static SaltProject org.corpus_tools.salt.util.SaltUtil.loadCompleteSaltProject ( URI  location)
static

Loads a SaltProject from given uri and returns it as object structure.

Parameters
locationlocation to the Salt project file
Returns
returns a saltProject, which is filled with data coming from corpus in uri

◆ loadCorpusGraph() [1/2]

static SCorpusGraph org.corpus_tools.salt.util.SaltUtil.loadCorpusGraph ( URI  corpusPath)
static

Loads the given SaltXML file (.

{@value SaltFactory::FILE_ENDING_SALT}) into this object. If the given SaltXML file does not contain a SCorpusGraph object persisting, an exception will be thrown. If the SaltXML file contains persistings for more than one SCorpusGraph object, the first one will be loaded.

Parameters
corpusPaththe URI to locate the SaltXML file
Returns

◆ loadCorpusGraph() [2/2]

static SCorpusGraph org.corpus_tools.salt.util.SaltUtil.loadCorpusGraph ( URI  corpusPath,
Integer  idxOfSCorpusGraph 
)
static

Loads the given SaltXML file (.

{@value SaltFactory::FILE_ENDING_SALT}) into this object. If the given SaltXML file does not contain a SCorpusGraph object persisting, an exception will be thrown. The parameter idxOfSCorpusGraph determines which object shall be load, in case of the given SaltXML file contains more than one persisting of SCorpusGraph objects.

Parameters
corpusPaththe URI to locate the SaltXML file
idxOfSCorpusGraphnumber of graph to be load, note that the list of graphs starts with 0
Returns

◆ loadDocumentGraph()

static SDocumentGraph org.corpus_tools.salt.util.SaltUtil.loadDocumentGraph ( URI  location)
static

Loads a SDocumentGraph object and returns it.

The location of where to find the SaltXML containing the SDocumentGraph object is given by the passed URI object.

Parameters
locationlocation of SaltXML to load SDocumentGraph object.

◆ loadObjects()

static List<Object> org.corpus_tools.salt.util.SaltUtil.loadObjects ( URI  location)
static

Loads a list of root objects coming from a SaltXML (.

FILE_ENDING_SALT_XML) and returns it.

Parameters
objectURIURI to SaltXML file containing the object
Returns
loaded objects

◆ loadSaltProject()

static SaltProject org.corpus_tools.salt.util.SaltUtil.loadSaltProject ( URI  location)
static

Loads a SaltProject from given uri and returns it as object structure.

This does not load the document graphs which are to the SaltProject from the disk. To load the entire project use loadCompleteSaltProject(URI) or call SDocument#loadDocumentGraph() on each document to load the actual document graph.

Parameters
locationlocation to the Salt project file
Returns
returns a saltProject, which is filled with data coming from corpus in uri

◆ moveAnnotations()

static void org.corpus_tools.salt.util.SaltUtil.moveAnnotations ( SAnnotationContainer  from,
SAnnotationContainer  to 
)
static

Moves all SAnnotation objects from from to to.

Parameters
fromSAnnotatableElement object from which SAnnotation object should be moved
toSAnnotatableElement object to which SAnnotation object should be moved

◆ moveCorpusGraph()

static void org.corpus_tools.salt.util.SaltUtil.moveCorpusGraph ( SCorpusGraph  source,
SCorpusGraph  target 
)
static

Moves the content of source to target.

Caution: Object contained in source will be moved, which from target to source, which will mean, that object are not content of source any more after using moveCorpusGraph(SCorpusGraph, SCorpusGraph).

Parameters
sourceSCorpusGraph delivering the content to moveSCorpusGraph
targetSCorpusGraph object to where the content will be moved

◆ moveMetaAnnotations()

static void org.corpus_tools.salt.util.SaltUtil.moveMetaAnnotations ( SAnnotationContainer  from,
SAnnotationContainer  to 
)
static

Moves all SMetaAnnotation objects from from to to.

Parameters
fromSMetaAnnotatableElement object from which SMetaAnnotation object should be moved
toSMetaAnnotatableElement object to which SMetaAnnotation object should be moved

◆ save_DOT()

static void org.corpus_tools.salt.util.SaltUtil.save_DOT ( Object  saltObject,
URI  location 
)
static

This method stores a Salt model in the dot syntax (see: http://www.graphviz.org/) in a file.

The stored dot graph can be visualized via the Graphviz toolbox (see: http://www.graphviz.org/) into a bunch of graphical formats like jpeg, png, svg etc..
In case of a SaltProject like the following is stored:

|-----------------------------------------------|
| SaltProject:                                  |
|-----------------------------------------------|
| corpus-structure 0      | corpus-structure 1  |
|                         |                     |
|          c1             |       c1            |
|        /     \          |       |             |
|       c2      c3        |       d1            |
|   /   |   \   |   \     |                     |
|  d1   d2  d3  d4  d5    |                     |
|-----------------------------------------------|

A structure like the following is created:

 |-0
 | |-c1
 | | |-c2
 | |   |-d1.dot
 | |   |-d2.dot
 | |   |-d3.dot
 | | |-c3
 | |   |-d4.dot
 | |   |-d5.dot
 | |-0.dot
 |-1
   |-c1
   | |-d1.dot
   |-1.dot

◆ saveCorpusGraph()

static void org.corpus_tools.salt.util.SaltUtil.saveCorpusGraph ( SCorpusGraph  corpusGraph,
URI  location 
)
static

Persists the passed SCorpusGraph object in a {@value SaltUtil::FILE_ENDING_SALT_XML} file at the passed location.

The relation between all SDocuments and their SDocumentGraph will be removed.

Parameters
corpusGraphSCorpusGraph object to persist
locationlocation of where to persist object as URI

◆ saveCorpusGraph_DOT()

static void org.corpus_tools.salt.util.SaltUtil.saveCorpusGraph_DOT ( SCorpusGraph  corpusGraph,
URI  location 
)
static

Stores a SCorpusGraph into DOT file.

Parameters
corpusGraphthe corpus graph to be stored
locationthe location to where the corpus graph is stored

◆ saveDocumentGraph()

static void org.corpus_tools.salt.util.SaltUtil.saveDocumentGraph ( SDocumentGraph  documentGraph,
URI  location 
)
static

Persists the passed SDocumentGraph object in a SaltXML file at the passed location.

Parameters
documentGraphSDocumentGraph object to persist
locationlocation of where to persist object as URI

◆ saveDocumentGraph_DOT()

static void org.corpus_tools.salt.util.SaltUtil.saveDocumentGraph_DOT ( SDocumentGraph  documentGraph,
URI  location 
)
static

Stores a SDocumentGraph into DOT file.

Parameters
documentGraphthe document graph to be stored
locationthe location to where the document graph is stored

◆ saveSaltProject()

static void org.corpus_tools.salt.util.SaltUtil.saveSaltProject ( SaltProject  saltProject,
URI  location 
)
static

Persists the passed SaltProject object in a SaltXML file at the passed location.

The relation between all SDocuments and their SDocumentGraph will be removed.

Parameters
saltProjectSaltProject object to persist
locationlocation of where to persist object as URI

◆ splitQName()

static Pair<String, String> org.corpus_tools.salt.util.SaltUtil.splitQName ( String  qName)
static

Splits the passed qName into a namespace and a name.

Returns
Pair#getLeft() is the namespace, whereas Pair#getRight() is the name

◆ unmarshalAnnotation()

static Collection<String[]> org.corpus_tools.salt.util.SaltUtil.unmarshalAnnotation ( String  marshalledString)
static

Splits an annotation string of the form 'namespace::name=value (,namespace::name=value)* into a collection of (namespace, name, value).

Parameters
marshalledStringthe annotation string to be unmarschalled
Returns
a collection of (namespace, name, value).

◆ validate()

static <T extends Object> Validator.Builder<T> org.corpus_tools.salt.util.SaltUtil.validate ( saltObject)
static

Validates a salt project, a document structure or a corpus structure.

Parameters
saltObjectSalt object to be validated
Returns

Member Data Documentation

◆ FEAT_SDATA

final String org.corpus_tools.salt.util.SaltUtil.FEAT_SDATA = "SDATA"
static

The name of the SFeature for the data label for textual sources, etc.

◆ FEAT_SDATA_QNAME

final String org.corpus_tools.salt.util.SaltUtil.FEAT_SDATA_QNAME = SALT_NAMESPACE + NAMESPACE_SEPERATOR + FEAT_SDATA
static

Qualified name name of the SFeature for the data label for textual sources, etc.

◆ FEAT_SDOCUMENT_GRAPH_LOCATION_QNAME

final String org.corpus_tools.salt.util.SaltUtil.FEAT_SDOCUMENT_GRAPH_LOCATION_QNAME
static
Initial value:

Qualified name name for SFeature to store the uri reference of a SDocumentGraph in a SDocument.

org.corpus_tools.salt.util.SaltUtil.NAMESPACE_SEPERATOR
static final String NAMESPACE_SEPERATOR
Separator between namespace and name: qname= NAMESPACE {@value NAMESPACE_SEPERATOR} NAME.
Definition: SaltUtil.java:107
org.corpus_tools.salt.util.SaltUtil.SALT_NAMESPACE
static final String SALT_NAMESPACE
default name for of derived namespace-attribute
Definition: SaltUtil.java:102
org.corpus_tools.salt.util.SaltUtil.FEAT_SDOCUMENT_GRAPH_LOCATION
static final String FEAT_SDOCUMENT_GRAPH_LOCATION
Name for SFeature to store the uri reference of a SDocumentGraph in a SDocument.
Definition: SaltUtil.java:193