本文整理汇总了Java中net.didion.jwnl.JWNL类的典型用法代码示例。如果您正苦于以下问题:Java JWNL类的具体用法?Java JWNL怎么用?Java JWNL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JWNL类属于net.didion.jwnl包,在下文中一共展示了JWNL类的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: toString
import net.didion.jwnl.JWNL; //导入依赖的package包/类
public String toString() {
if (_cachedToString == null) {
StringBuffer words = new StringBuffer();
for (int i = 0; i < getWordsSize(); ++i) {
if (i > 0) words.append(", ");
words.append(getWord(i).getLemma());
}
if (getGloss() != null)
words.append(" -- (" + getGloss() + ")");
_cachedToString =
JWNL.resolveMessage("DATA_TOSTRING_009", new Object[]{new Long(getOffset()), getPOS(), words.toString()});
}
return _cachedToString;
}
示例6: toString
import net.didion.jwnl.JWNL; //导入依赖的package包/类
public String toString() {
if (_cachedToString == null) {
String str = "";
if (size() == 0) {
str = JWNL.resolveMessage("DATA_TOSTRING_003");
} else {
StringBuffer buf = new StringBuffer();
Iterator itr = getValidPOSSet().iterator();
while (itr.hasNext()) {
buf.append(getIndexWord((POS)itr.next()).toString());
}
str = buf.toString();
}
_cachedToString = JWNL.resolveMessage("DATA_TOSTRING_004", str);
}
return _cachedToString;
}
示例7: 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();
}
}
示例8: 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;
}
示例9: unload
import net.didion.jwnl.JWNL; //导入依赖的package包/类
@Override
public void unload() {
this.mCache.clear();
if (mDictionary != null)
mDictionary.close();
if (mInit) {
Dictionary.uninstall();
JWNL.shutdown();
}
}
示例10: unload
import net.didion.jwnl.JWNL; //导入依赖的package包/类
@Override
public void unload() {
if(mDictionary!=null)
mDictionary.close();
if(mInit){
Dictionary.uninstall();
JWNL.shutdown();
}
}
示例11: 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(); }
}
示例12: 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();
}
}
示例13: 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();
}
示例14: 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(); }
}
示例15: 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);
}