All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.uni_leipzig.asv.utils.IniFile Maven / Gradle / Ivy

Go to download

ASV Toolbox is a modular collection of tools for the exploration of written language data. They work either on word lists or text and solve several linguistic classification and clustering tasks. The topics covered contain language detection, POS-tagging, base form reduction, named entity recognition, and terminology extraction. On a more abstract level, the algorithms deal with various kinds of word similarity, using pattern based and statistical approaches. The collection can be used to work on large real world data sets as well as for studying the underlying algorithms. The ASV Toolbox can work on plain text files and connect to a MySQL database. While it is especially designed to work with corpora of the Leipzig Corpora Collection, it can easily be adapted to other sources.

The newest version!
/*******************************************************************************
 * The MIT License (MIT)

 * Copyright (c) 2007, University of Leipzig, Institut für Informatik,
 * Abteilung Autmatische Sprachverarbeitung

 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
******************************************************************************/
package de.uni_leipzig.asv.utils;

// standard imports
import java.io.File;
import java.util.Hashtable;

/**
 * An IniFile is a cache which reads some specified file of the given format.
 * The values of the file can then be directly accessed at any time, as well as
 * changed. Changes will immediately be written into the file. This class is not
 * intended for massive writing, as each change requires rewriting of the whole
 * file.
*
# Format of Inifiles should look like this:
*
# comment
*
* [PRIMARY_KEY]
* SECONDARY_KEY_1=value
* SECONDARY_KEY_2=value
*
* * @author Stefan Bordag * @date 28.12.2001 * @see de.uni_leipzig.asv.bordag.sgz.util.IniReader * @see de.uni_leipzig.asv.bordag.sgz.util.IniWriter */ public class IniFile { /** * Constants defining the format of the file */ public static final String PKEY_LEFT_BRACKET = "["; public static final String PKEY_RIGHT_BRACKET = "]"; public static final String ASSIGNMENT = "="; public static final String COMMENT = "#"; /** * A double Hashtable containing the structure and values of the file */ protected Hashtable> entries = null; /** * The file which was used to read the information and which is then used to * write changes */ protected String file = null; /** * Default constructor, don't use it, as instances without a filename are * senseless */ public IniFile() { init(null); } /** * Convenience constructor */ public IniFile(File file) { init(file.getAbsolutePath()); } /** * Creates an instance of the IniReader and reads the file, thus cashing the * data */ public IniFile(String fileName) { init(fileName); } /** * Initializes the reader */ private void init(String fileName) { this.file = fileName; IniReader reader = null; try { reader = new IniReader(fileName); this.entries = reader.getPrimaryKeys(); } catch (Exception ignore) { this.entries = new Hashtable>(); } } /** * Returns a Hashtable containing all the entries belonging to the given * primary key */ public Hashtable getPrimaryKey(String key) { return this.entries.get(key); } /** * Returns the required value of the given primary key */ public String getValue(String primaryKey, String secondaryKey) { return this.entries.get(primaryKey).get(secondaryKey); } /** * Sets the values of the entire given primary key section to the given * hashtable of values */ public void setValues(String primaryKey, Hashtable hash) { if ((primaryKey == null) || (hash == null) || (primaryKey.length() < 1) || (hash.size() < 1)) { return; } this.entries.put(primaryKey, hash); new IniWriter(this); } /** * Sets or Adds a given value to a given keypair */ @SuppressWarnings("unchecked") public void setValue(String primaryKey, String secondaryKey, String value) { if ((primaryKey == null) || (secondaryKey == null) || (value == null) || (primaryKey.length() < 1) || (secondaryKey.length() < 1)) { return; } Object secVal = this.entries.get(primaryKey); Hashtable tempHash = null; if (secVal == null) { tempHash = new Hashtable(); } else { tempHash = (Hashtable) secVal; } tempHash.put(secondaryKey, value); this.entries.put(primaryKey, tempHash); new IniWriter(this); } /** * Tests whtether this inifile contains a value with the given Keypair */ public boolean existsKeyPair(String primKey, String secKey) { Hashtable val = this.entries.get(primKey); if (val != null) { if (val.containsKey(secKey)) { return true; } } return false; } /** * Returns the whole Hashtable */ public Hashtable> getPrimaryKeys() { return this.entries; } /** * Returns the name of the file which is associated with this instance of * IniFile */ public String getFileName() { return this.file; } /** * Prints out a representation of this class */ @Override public String toString() { return "IniFile with filename " + this.file; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy