本文整理汇总了Java中net.didion.jwnl.JWNL.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java JWNL.initialize方法的具体用法?Java JWNL.initialize怎么用?Java JWNL.initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.didion.jwnl.JWNL
的用法示例。
在下文中一共展示了JWNL.initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
public static void main(String[] args) {
if (args.length != 1) {
System.out.println(USAGE);
System.exit(-1);
}
String propsFile = args[0];
try {
// initialize JWNL (this must be done before JWNL can be used)
JWNL.initialize(new FileInputStream(propsFile));
new Examples().go();
} catch (Exception ex) {
ex.printStackTrace();
System.exit(-1);
}
}
示例2: processInput
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
public void processInput() {
if( infoPath.length() <= 0 )
System.err.println("No info file given");
else {
// Load WordNet first
try {
JWNL.initialize(new FileInputStream(wordnetPath)); // WordNet
} catch( Exception ex ) { ex.printStackTrace(); }
// Read the Parser
_parser = Ling.createParser(serializedGrammar);
_options = _parser.getOp();
System.out.println("Processing info file " + infoPath);
infoFile.readFromFile(new File(infoPath));
if( onlyEvents ) infoToEventFeatures(infoFile);
else infoToRelationFeatures(infoFile);
// Save the indices, we may have added new words
indices.indexToFile(indices.wordIndex(),"new-wordIndex.txt");
indices.indexToFile(indices.lemmaIndex(),"new-lemmaIndex.txt");
indices.indexToFile(indices.synsetIndex(),"new-synsetIndex.txt");
}
}
示例3: processInput
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
public void processInput() {
// Load WordNet first
try {
JWNL.initialize(new FileInputStream(wordnetPath)); // WordNet
} catch( Exception ex ) { ex.printStackTrace(); }
// Start the Parser
parser = Ling.createParser(serializedGrammar);
options = parser.getOp();
// Load the datafiles
loadData();
// Create the features
String shorty = parsefile.substring(parsefile.lastIndexOf("/")+1,
parsefile.length());
createEventFeatures(shorty);
// createRelationFeatures(infoFile);
}
示例4: getDictionary
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
private static Dictionary getDictionary() {
synchronized (WordNet.class) {
if (dictionary == null) {
JWNL.shutdown(); // in case it was previously initialized
try {
final String properties = Resources.toString(
WordNet.class.getResource("jwnl.xml"), Charsets.UTF_8).replace(
"DICTIONARY_PATH_PLACEHOLDER", dictionaryPath);
final InputStream stream = new ByteArrayInputStream(
properties.getBytes(Charsets.UTF_8));
JWNL.initialize(stream);
dictionary = Dictionary.getInstance();
} catch (final Throwable ex) {
JWNL.shutdown();
throw new Error("Cannot initialize JWNL using dictionary path '"
+ dictionaryPath + "'", ex);
}
}
return dictionary;
}
}
示例5: init
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
/** Initialise this resource, and return it. */
public Resource init() throws ResourceInstantiationException {
if (null == this.propertyUrl) {
throw new ResourceInstantiationException("property file not set");
}
try {
InputStream inProps = this.propertyUrl.openStream();
JWNL.initialize(inProps);
this.wnDictionary = Dictionary.getInstance();
Assert.assertNotNull(this.wnDictionary);
}
catch(Exception e) {
throw new ResourceInstantiationException(e);
}
return this;
}
示例6: testGetWordSenses
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
/**
* Pulls a noun "tank" from the dictionary and checks to see if it has 5 senses.
*
*/
public void testGetWordSenses() {
try {
JWNL.initialize(TestDefaults.getInputStream());
IndexWord word = Dictionary.getInstance().getIndexWord(POS.NOUN, "tank");
assertTrue(word.getSenseCount() == 5);
word = Dictionary.getInstance().getIndexWord(POS.VERB, "eat");
assertTrue(word.getSenseCount() == 6);
word = Dictionary.getInstance().getIndexWord(POS.ADJECTIVE, "quick");
assertTrue(word.getSenseCount() == 6);
word = Dictionary.getInstance().getIndexWord(POS.ADJECTIVE, "big");
assertTrue(word.getSenseCount() == 13);
} catch(JWNLException e) {
fail("Exception in testGetSenses caught");
e.printStackTrace();
}
}
示例7: WordNet
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
public WordNet(String wordnetPath) {
// Load WordNet
try {
if( wordnetPath.length() > 0 ) {
JWNL.initialize(new FileInputStream(wordnetPath));
System.out.println("WordNet initialized from " + wordnetPath);
}
else
System.out.println("ERROR: could not find wordnetPath");
} catch( Exception ex ) { ex.printStackTrace(); }
}
示例8: Wordnet
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
public Wordnet() {
String propsFile = "file_properties.xml";
try {
JWNL.initialize(new FileInputStream(propsFile));
dict = Dictionary.getInstance();
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例9: FeatureIndices
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
public FeatureIndices(String[] args) {
handleParameters(args);
// Load WordNet first
try {
JWNL.initialize(new FileInputStream(wordnetPath)); // WordNet
} catch( Exception ex ) { ex.printStackTrace(); }
// Load indices if -preload flag was given
if( preload ) loadIndices();
}
示例10: ConvertToRoots
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
ConvertToRoots(String args[]) {
handleParameters(args);
// Load WordNet
try {
JWNL.initialize(new FileInputStream(wordnetPath)); // WordNet
} catch( Exception ex ) { ex.printStackTrace(); }
}
示例11: initialize
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
/**
* Initializes static resources. The input properties that must be defined are:
* <ul>
* <li>jwnl.configuration : </p> the location of the configuration file for JWNL
* <li>edu.cmu.lti.javelin.qa.english.WordNetAnswerTypeMapping.mapFile :
* <p> the location of the file specifying a mapping from WordNet synsets
* to answer subtypes. The one-to-many mapping must be specified
* one element per line, with the domain and range values separated by a comma.
* Blank lines and lines beginning with "#" are ignored. WordNet synsets must be
* represented by concatenating the list of lemmas in the synset, separating them
* with a dash ("-"), followed by another "-" and the database file offset of the synset.
* (Note: this offset value will vary with the version of WordNet used.)</p>
* Thus, an example of an element of the mapping is:</p>
* <code>body_of_water-water-8651117,ocean</code>
* </ul>
* @throws Exception if one of the required properties is not defined.
*/
public static void initialize() throws Exception {
if (isInitialized()) return;
if (!JWNL.isInitialized()) {
String file_properties = System.getProperty("jwnl.configuration");
if (file_properties == null)
throw new Exception("Required property 'jwnl.configuration' is undefined");
JWNL.initialize(new FileInputStream(file_properties));
}
pUtils = PointerUtils.getInstance();
Properties properties = Properties.loadFromClassName(WordNetAnswerTypeMapping.class.getName());
String wnAtypeMapFile = properties.getProperty("mapFile");
if (wnAtypeMapFile == null)
throw new RuntimeException("Required parameter mapFile is undefined");
BufferedReader in = new BufferedReader(new FileReader(wnAtypeMapFile));
String line;
wnAtypeMap = new HashMap<String, String>();
wnAtypeMapKeys = new ArrayList<String>();
while ((line = in.readLine()) != null) {
if (line.matches("#.*") || line.matches("\\s*")) continue;
String[] strs = line.split(",");
wnAtypeMap.put(strs[0],strs[1]);
wnAtypeMapKeys.add(strs[0]);
}
in.close();
setInitialized(true);
}
示例12: initialize
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
/**
* Initializes static resources. The input properties which must be defined are:
* <ul>
* <li> edu.cmu.lti.javelin.qa.english.FocusFinder.treeTemplatesFile :
* the location of a file containing tree templates to use. Each tree template
* must be specified on one line. Blank lines and lines beginning with "#"
* are ignored. A tree template is a parenthesized syntactic parse tree which
* can be used as an underspecified template tree to unify with a real syntactic
* parse tree. See {@link edu.cmu.lti.chineseNLP.util.TreeHelper#extractNode
* TreeHelper.extractNode} for more details.
* </ul>
* @throws Exception if the required input property is not defined
*/
public static void initialize() throws Exception {
// return if already initialized
if (isInitialized()) return;
Properties properties = Properties.loadFromClassName(FocusFinder.class.getName());
// initialize JWNL
if (!JWNL.isInitialized()) {
String file_properties = System.getProperty("jwnl.configuration");
if (file_properties == null)
throw new Exception("Required property 'jwnl.configuration' is undefined");
JWNL.initialize(new FileInputStream(file_properties));
}
// load tree templates file
treeTemplatesFile = properties.getProperty("treeTemplatesFile");
if (treeTemplatesFile == null)
throw new Exception("Required property treeTemplatesFile is undefined");
BufferedReader in = new BufferedReader(new FileReader(treeTemplatesFile));
String line;
treeTemplates = new ArrayList<Tree>();
while ((line = in.readLine()) != null) {
if (line.matches("#.*") || line.matches("\\s*")) continue;
treeTemplates.add(TreeHelper.buildTree(line, Tree.ENGLISH));
}
in.close();
setInitialized(true);
}
示例13: initialize
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
/**
* Initializes the wrapper for the WordNet dictionary.
*
* @param properties property file
*/
public static boolean initialize(String properties) {
try {
File file = new File(properties);
JWNL.initialize(new FileInputStream(file));
dict = net.didion.jwnl.dictionary.Dictionary.getInstance();
} catch (Exception e) {
return false;
}
return true;
}
示例14: initializeJWNL
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
/**
* Used by JWNL-based Morphy implementations.
* @return
*/
public static boolean initializeJWNL()
{
try
{
JWNL.initialize(
getJWNLConfigFileStream(
WORDNET_PROPERTY,
JWNL_FILE_PROPERTIES_XML,
JWNL_DIR_PROPERTIES_XML
)
);
return true;
}
catch (Exception ex)
{
String estr = "Error: Unable to initialize JWNL: " + ex.toString() + "\n";
Throwable th = ex.getCause();
while (th != null)
{
estr += th.toString() + "\n";
th = th.getCause();
}
System.err.println(estr);
return false;
}
}
示例15: testGetBySynset
import net.didion.jwnl.JWNL; //导入方法依赖的package包/类
public void testGetBySynset() {
try {
JWNL.initialize(TestDefaults.getInputStream());
/**
* 2.1 offset for tank.
*/
long offset = 4337089;
Synset syn = Dictionary.getInstance().getSynsetAt(POS.NOUN, offset);
boolean match = false;
for (int i = 0; i < syn.getWords().length; i++) {
Word w = syn.getWords()[i];
if (w.getLemma().equals("tank")) {
match = true;
break;
}
}
if (!match) {
fail("Term 'tank' not found in test grab.");
}
} catch(Exception e) {
fail("Exception in Synset 2.1 test caught");
e.printStackTrace();
}
System.out.println("Synset 2.1 test passed.");
}