本文整理汇总了Java中it.uniroma1.lcl.babelnet.BabelSense类的典型用法代码示例。如果您正苦于以下问题:Java BabelSense类的具体用法?Java BabelSense怎么用?Java BabelSense使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BabelSense类属于it.uniroma1.lcl.babelnet包,在下文中一共展示了BabelSense类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import it.uniroma1.lcl.babelnet.BabelSense; //导入依赖的package包/类
/**
* Process the data and write the outputs.
*
* @throws IOException when an I/O error has occurred.
*/
public void run() throws IOException {
writeRecords(synsetsFilename, csv -> {
babelnet.getSynsetIterator().forEachRemaining(synset -> {
try {
final List<BabelSense> senses = synset.getSenses(language);
if (senses.isEmpty()) return;
final String synsetID = synset.getId().toString();
final Set<String> lemmas = senses.stream().map(BabelSense::getSimpleLemma).collect(toSet());
csv.printRecord(synsetID, lemmas.size(), lemmas.stream().collect(joining(", ")));
logger.log(Level.INFO, "Extracted {0}", synsetID);
} catch (final IOException ex) {
throw new RuntimeException(ex);
}
});
});
logger.log(Level.INFO, "Done");
}
示例2: lookupSense
import it.uniroma1.lcl.babelnet.BabelSense; //导入依赖的package包/类
private List<BabelSense> lookupSense(Language language, String lemma, POS postag) throws IOException {
List<BabelSense> senses = babelNet.getSenses(language, lemma, postag, BabelSenseSource.WN);
if (senses == null || senses.isEmpty()) {
senses = babelNet.getSenses(language, lemma.replace(" ", "_"), postag, BabelSenseSource.WN);
}
if (senses == null || senses.isEmpty()) {
senses = babelNet.getSenses(language, lemma, postag, BabelSenseSource.WNTR);
}
if (senses == null || senses.isEmpty()) {
senses = babelNet.getSenses(language, lemma.replace(" ", "_"), postag, BabelSenseSource.WNTR);
}
if (senses == null || senses.isEmpty()) {
senses = babelNet.getSenses(language, lemma, postag);
}
if (senses == null || senses.isEmpty()) {
senses = babelNet.getSenses(language, lemma.replace(" ", "_"), postag);
}
/*
if (senses == null || senses.isEmpty()) {
senses = babelNet.getSenses(language, lemma);
}
if (senses == null || senses.isEmpty()) {
senses = babelNet.getSenses(language, lemma.replace(" ", "_"));
}
*/
if (senses == null || senses.isEmpty()) {
Logger.getLogger(RevisedLesk.class.getName()).log(Level.WARNING, "No senses for {0}, pos-tag {1}", new Object[]{lemma, postag});
}
//remove duplicate senses
if (senses != null && !senses.isEmpty()) {
Set<String> ids = new HashSet<>();
for (int i = senses.size() - 1; i >= 0; i--) {
if (!ids.add(senses.get(i).getSynset().getId())) {
senses.remove(i);
}
}
}
return senses;
}
示例3: main
import it.uniroma1.lcl.babelnet.BabelSense; //导入依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
BabelNet babelNet = BabelNet.getInstance();
List<BabelSense> senses = babelNet.getSenses(Language.IT, args[0],POS.NOUN,BabelSenseSource.WNTR);
for (BabelSense sense:senses) {
System.out.println(sense.getSynset().getId()+"\t"+sense.getPosition());
}
} catch (IOException ex) {
Logger.getLogger(TestBabelNet.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例4: getMaxSenseOccurrences
import it.uniroma1.lcl.babelnet.BabelSense; //导入依赖的package包/类
/**
*
* @param sense
* @return
*/
public float getMaxSenseOccurrences(BabelSense sense) {
float maxOcc = 0;
for (int l = 0; l < sense.getSynset().getWordNetOffsets().size(); l++) {
Float occ = getSynsetOccurrences(sense.getSynset().getWordNetOffsets().get(l));
if (occ != null && occ > maxOcc) {
maxOcc = occ;
}
}
return maxOcc;
}
示例5: getMaxSenseProbability
import it.uniroma1.lcl.babelnet.BabelSense; //导入依赖的package包/类
/**
*
* @param key
* @param sense
* @param maxSize
* @return
*/
public float getMaxSenseProbability(String key, BabelSense sense, int maxSize) {
float maxProb = 0;
for (int l = 0; l < sense.getSynset().getWordNetOffsets().size(); l++) {
float prob = getSynsetProbability(key, sense.getSynset().getWordNetOffsets().get(l), maxSize);
if (prob > maxProb) {
maxProb = prob;
}
}
return maxProb;
}