Java tutorial
/* * Copyright Paolo Dragone 2014 * * This file is part of WiktionarySemanticNetwork. * * WiktionarySemanticNetwork is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * WiktionarySemanticNetwork is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with WiktionarySemanticNetwork. If not, see <http://www.gnu.org/licenses/>. */ package com.paolodragone.wsn; import com.paolodragone.util.DConfiguration; import org.apache.commons.configuration.ConfigurationException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; /** * @author Paolo Dragone */ public class WsnConfiguration extends DConfiguration { private static final String configFileName = "/wsn.properties"; private static WsnConfiguration instance; public final String SensesFilePathProp = "senses.path"; public final String SynonymsFilePathProp = "synonyms.path"; public final String SensesSynonymsFilePathProp = "senses_synonyms.path"; public final String TermsFilePathProp = "terms.path"; public final String TermWeightsFilePathProp = "term_weights.path"; public final String WiktionaryDumpFilePathProp = "wiktionary_dump.path"; public final String TestSetFilePathProp = "test_set.path"; public final String SemanticNetworkFilePathProp = "semantic_network.path"; public final String SemanticNetworkTestSetFilePathProp = "semantic_network_test_set.path"; private WsnConfiguration() throws ConfigurationException { loadResource(configFileName); } public static WsnConfiguration getInstance() throws ConfigurationException { if (instance == null) { instance = new WsnConfiguration(); } return instance; } public Path getSensesFilePath() throws IOException { return getFilePath(getProperties().getString(SensesFilePathProp)); } public Path getSynonymsFilePath() throws IOException { return getFilePath(getProperties().getString(SynonymsFilePathProp)); } public Path getSensesSynonymsFilePath() throws IOException { return getFilePath(getProperties().getString(SensesSynonymsFilePathProp)); } public Path getTermWeightsFilePath() throws IOException { return getFilePath(getProperties().getString(TermWeightsFilePathProp)); } public Path getWiktionaryDumpFilePath() throws IOException { return getFilePath(getProperties().getString(WiktionaryDumpFilePathProp)); } public Path getTermsFilePath() throws IOException { return getFilePath(getProperties().getString(TermsFilePathProp)); } public Path getTestSetFilePath() throws IOException { return getFilePath(getProperties().getString(TestSetFilePathProp)); } public Path getSemanticNetworkFilePath() throws IOException { return getFilePath(getProperties().getString(SemanticNetworkFilePathProp)); } public Path getSemanticNetworkTestSetFilePath() throws IOException { return getFilePath(getProperties().getString(SemanticNetworkTestSetFilePathProp)); } private Path getFilePath(String filePathString) throws IOException { Path path = Paths.get(filePathString); if (Files.notExists(path)) { Files.createDirectories(path.getParent()); Files.createFile(path); } return path; } }