當前位置: 首頁>>代碼示例>>Java>>正文


Java BabelSense類代碼示例

本文整理匯總了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");
}
 
開發者ID:nlpub,項目名稱:babelnet-extract,代碼行數:27,代碼來源:SynsetsAction.java

示例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;
}
 
開發者ID:pippokill,項目名稱:lesk-wsd-dsm,代碼行數:40,代碼來源:RevisedLesk.java

示例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);
    }
}
 
開發者ID:pippokill,項目名稱:lesk-wsd-dsm,代碼行數:15,代碼來源:TestBabelNet.java

示例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;
}
 
開發者ID:pippokill,項目名稱:lesk-wsd-dsm,代碼行數:16,代碼來源:SenseFreqAPI.java

示例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;
}
 
開發者ID:pippokill,項目名稱:lesk-wsd-dsm,代碼行數:18,代碼來源:SenseFreqAPI.java


注:本文中的it.uniroma1.lcl.babelnet.BabelSense類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。