Class TSVReader
That parser can also be indirectly used to parse a JSON file: if it detects
that the first byte of the file is a {
character, it will assume
the file is a JSON file (no valid SSSOM/TSV file can start with a
{
) and will automatically invoke a JSONReader
.
Usage:
try { TSVReader reader = new TSVReader("my-mappings.sssom.tsv"); MappingSet mappingSet = reader.read(); } catch ( IOException ioe ) { // Generic, non-SSSOM-related I/O error (e.g. file not found) } catch ( SSSOMFormatException sfe ) { // Invalid SSSOM data }
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Defines what separator character the reader should expect when parsing the TSV section. -
Field Summary
Fields inherited from class org.incenp.obofoundry.sssom.SSSOMReader
assumedVersion, extraPolicy, propagationPolicy
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance that will read data from a single file.Creates a new instance that will read data from the specified files.TSVReader
(InputStream stream) Creates a new instance that will read data from a single stream.TSVReader
(InputStream tsvStream, InputStream metaStream) Creates a new instance that will read data from the specified streams.Creates a new instance that will read data from the specified reader.Creates a new instance that will read data from the specified reader.Creates a new instance that will read data from the specified reader.Creates a new instance that will read data from a single file.Creates a new instance that will read data from the specified files. -
Method Summary
Modifier and TypeMethodDescriptionvoid
fillPrefixMap
(Map<String, String> map) Declares all prefix names in the specified map.read()
Reads a mapping set from the source file(s).read
(boolean metadataOnly) Reads a mapping set from the source file(s), with the option of reading the metadata only.void
Sets the behaviour of the reader regarding the column separator character.Methods inherited from class org.incenp.obofoundry.sssom.SSSOMReader
setAssumedVersion, setExtraMetadataPolicy, setPropagationEnabled, setValidation, setValidationEnabled, validate
-
Constructor Details
-
TSVReader
Creates a new instance that will read data from the specified files.- Parameters:
tsvFile
- The main TSV file. May benull
if one only wants to read a metadata file (in which case the second argument cannot also benull
).metaFile
- The accompanying metadata file. Ifnull
, the parser will attempt to automatically locate the metadata from the main file.- Throws:
FileNotFoundException
- If any of the files cannot be found.
-
TSVReader
Creates a new instance that will read data from a single file. That file should either contain an embedded metadata block, or a file containing the metadata should exist alongside it.- Parameters:
file
- The single file to read.- Throws:
FileNotFoundException
- If the file cannot be found.
-
TSVReader
Creates a new instance that will read data from the specified streams. Note that when reading from a stream, the metadata either needs to be embedded with the TSV stream or an explicit metadata stream must be specified; the reader cannot automatically locate an external metadata file.- Parameters:
tsvStream
- The main stream, containing the TSV data. May benull
if one only wants to read a metadata stream (in which case the second argument cannot also benull
).metaStream
- The accompanying metadata stream. Ifnull
, the metadata must be embedded in the TSV stream.
-
TSVReader
Creates a new instance that will read data from a single stream. That file must contain an embedded metadata block.- Parameters:
stream
- The single stream to read from.
-
TSVReader
Creates a new instance that will read data from the specified reader. Note that when reading from a reader object, the metadata either needs to be embedded with the TSV or an explicit reader for the metadata must be specified; the reader cannot automatically locate an external metadata file.- Parameters:
tsvReader
- The main reader, containing the TSV data. May benull
if one only wants to read the metadata (in which case the second argument cannot also benull
).metaReader
- The accompagnying metadata reader. Ifnull
, the metadata must be embedded with the TSV section.
-
TSVReader
Creates a new instance that will read data from the specified reader.This constructor behaves similarly to
TSVReader(Reader, Reader)
, but allows providing the filename of the TSV file in the third argument, which will be used to try locating the external metadata file if (1) the TSV file does not contain an embedded metadata block and (2) themetaReader
argument isnull
.- Parameters:
tsvReader
- The main reader, containing the TSV data. May benull
if one only wants to read the metadata (in which case the second argument cannot also benull
.metaReader
- The accompanying metadata reader. Ifnull
, the metadata must either be embedded with the TSV section or be in a file in the same directory and with the same basename than the name provided in the third argument.filename
- The name of the file containing the TSV section; that name is not used to actually read the TSV section, but to try locating the external metadata file if needed (if the TSV file contains no embedded metadata and the second argument isnull
).
-
TSVReader
Creates a new instance that will read data from the specified reader.The metadata must be embedded with the TSV section; the reader cannot automatically locate an external metadata file. To read from a Reader object while still being able to automatically locate and use an external metadata file, use
TSVReader(Reader, Reader, String)
with the second argument set tonull
and the third argument set to the filename of the TSV section.- Parameters:
tsvReader
- The single reader to read from.
-
TSVReader
Creates a new instance that will read data from the specified files.- Parameters:
tsvFile
- The name of the main TSV file. May benull
if one only wants to read a metadata file (in which case the second argument cannot also benull
).metaFile
- The name of the accompanying metadata file. Ifnull
, the parser will attempt to automatically locate the metadata from the main file.- Throws:
FileNotFoundException
- If any of the files cannot be found.
-
TSVReader
Creates a new instance that will read data from a single file. That file should either contain an embedded metadata block, or a file containing the metadata should exist alongside it.- Parameters:
file
- The name of the single file to read.- Throws:
FileNotFoundException
- If the file cannot be found.
-
-
Method Details
-
fillPrefixMap
Description copied from class:SSSOMReader
Declares all prefix names in the specified map. Prefix names declared here complement the declarations from the file’s own prefix map, allowing the reader to parse a file with an incomplete prefix map.It is up to concrete implementations to actually do something with that map. Some of them may ignore it.
- Overrides:
fillPrefixMap
in classSSSOMReader
- Parameters:
map
- The prefix map to use.
-
setSeparatorMode
Sets the behaviour of the reader regarding the column separator character.By default, the reader tries to guess whether columns in the TSV section are separated by tabs or by commas (defaulting to tabs if it cannot positively determine the separator). Use this method to force the reader to expect a given separator.
- Parameters:
mode
- The separator mode to be used by this reader.
-
read
Reads a mapping set from the source file(s).- Specified by:
read
in classSSSOMReader
- Returns:
- A complete SSSOM mapping set, unless no TSV file was provided to the constructor when this object was created, in which case the returned object will contain no mappings.
- Throws:
SSSOMFormatException
- If encountering invalid SSSOM data. This includes the case where the metadata cannot be found.IOException
- If any kind of non-SSSOM-related I/O error occurs.
-
read
Reads a mapping set from the source file(s), with the option of reading the metadata only.- Parameters:
metadataOnly
- Iftrue
, the mappings themselves will not be read, only the metadata. The returnedMappingSet
object will contain no mappings. If no TSV file was provided to the constructor when this object was created, then no mappings will be read regardless of the value of this parameter.- Returns:
- A SSSOM mapping set, with or without any mappings depending on the parameter.
- Throws:
SSSOMFormatException
- If encountering invalid SSSOM data.IOException
- If any kind of non-SSSOM-related I/O error occurs.
-