Search in sources :

Example 6 with EnumItem

use of com.hankcs.hanlp.corpus.dictionary.item.EnumItem in project HanLP by hankcs.

the class PersonRecognition method Recognition.

public static boolean Recognition(List<Vertex> pWordSegResult, WordNet wordNetOptimum, WordNet wordNetAll) {
    List<EnumItem<NR>> roleTagList = roleObserve(pWordSegResult);
    if (HanLP.Config.DEBUG) {
        StringBuilder sbLog = new StringBuilder();
        Iterator<Vertex> iterator = pWordSegResult.iterator();
        for (EnumItem<NR> nrEnumItem : roleTagList) {
            sbLog.append('[');
            sbLog.append(iterator.next().realWord);
            sbLog.append(' ');
            sbLog.append(nrEnumItem);
            sbLog.append(']');
        }
        System.out.printf("人名角色观察:%s\n", sbLog.toString());
    }
    List<NR> nrList = viterbiComputeSimply(roleTagList);
    if (HanLP.Config.DEBUG) {
        StringBuilder sbLog = new StringBuilder();
        Iterator<Vertex> iterator = pWordSegResult.iterator();
        sbLog.append('[');
        for (NR nr : nrList) {
            sbLog.append(iterator.next().realWord);
            sbLog.append('/');
            sbLog.append(nr);
            sbLog.append(" ,");
        }
        if (sbLog.length() > 1)
            sbLog.delete(sbLog.length() - 2, sbLog.length());
        sbLog.append(']');
        System.out.printf("人名角色标注:%s\n", sbLog.toString());
    }
    PersonDictionary.parsePattern(nrList, pWordSegResult, wordNetOptimum, wordNetAll);
    return true;
}
Also used : Vertex(com.hankcs.hanlp.seg.common.Vertex) NR(com.hankcs.hanlp.corpus.tag.NR) EnumItem(com.hankcs.hanlp.corpus.dictionary.item.EnumItem)

Example 7 with EnumItem

use of com.hankcs.hanlp.corpus.dictionary.item.EnumItem in project HanLP by hankcs.

the class OrganizationRecognition method Recognition.

public static boolean Recognition(List<Vertex> pWordSegResult, WordNet wordNetOptimum, WordNet wordNetAll) {
    List<EnumItem<NT>> roleTagList = roleTag(pWordSegResult, wordNetAll);
    if (HanLP.Config.DEBUG) {
        StringBuilder sbLog = new StringBuilder();
        Iterator<Vertex> iterator = pWordSegResult.iterator();
        for (EnumItem<NT> NTEnumItem : roleTagList) {
            sbLog.append('[');
            sbLog.append(iterator.next().realWord);
            sbLog.append(' ');
            sbLog.append(NTEnumItem);
            sbLog.append(']');
        }
        System.out.printf("机构名角色观察:%s\n", sbLog.toString());
    }
    List<NT> NTList = viterbiExCompute(roleTagList);
    if (HanLP.Config.DEBUG) {
        StringBuilder sbLog = new StringBuilder();
        Iterator<Vertex> iterator = pWordSegResult.iterator();
        sbLog.append('[');
        for (NT NT : NTList) {
            sbLog.append(iterator.next().realWord);
            sbLog.append('/');
            sbLog.append(NT);
            sbLog.append(" ,");
        }
        if (sbLog.length() > 1)
            sbLog.delete(sbLog.length() - 2, sbLog.length());
        sbLog.append(']');
        System.out.printf("机构名角色标注:%s\n", sbLog.toString());
    }
    OrganizationDictionary.parsePattern(NTList, pWordSegResult, wordNetOptimum, wordNetAll);
    return true;
}
Also used : Vertex(com.hankcs.hanlp.seg.common.Vertex) NT(com.hankcs.hanlp.corpus.tag.NT) EnumItem(com.hankcs.hanlp.corpus.dictionary.item.EnumItem)

Example 8 with EnumItem

use of com.hankcs.hanlp.corpus.dictionary.item.EnumItem in project HanLP by hankcs.

the class NRDictionary method loadDat.

private EnumItem<NR>[] loadDat(String path) {
    byte[] bytes = IOUtil.readBytes(path);
    if (bytes == null)
        return null;
    NR[] nrArray = NR.values();
    int index = 0;
    int size = ByteUtil.bytesHighFirstToInt(bytes, index);
    index += 4;
    EnumItem<NR>[] valueArray = new EnumItem[size];
    for (int i = 0; i < size; ++i) {
        int currentSize = ByteUtil.bytesHighFirstToInt(bytes, index);
        index += 4;
        EnumItem<NR> item = new EnumItem<NR>();
        for (int j = 0; j < currentSize; ++j) {
            NR nr = nrArray[ByteUtil.bytesHighFirstToInt(bytes, index)];
            index += 4;
            int frequency = ByteUtil.bytesHighFirstToInt(bytes, index);
            index += 4;
            item.labelMap.put(nr, frequency);
        }
        valueArray[i] = item;
    }
    return valueArray;
}
Also used : NR(com.hankcs.hanlp.corpus.tag.NR) EnumItem(com.hankcs.hanlp.corpus.dictionary.item.EnumItem)

Example 9 with EnumItem

use of com.hankcs.hanlp.corpus.dictionary.item.EnumItem in project HanLP by hankcs.

the class NSDictionary method loadDat.

private EnumItem<NS>[] loadDat(String path) {
    byte[] bytes = IOUtil.readBytes(path);
    if (bytes == null)
        return null;
    NS[] NSArray = NS.values();
    int index = 0;
    int size = ByteUtil.bytesHighFirstToInt(bytes, index);
    index += 4;
    EnumItem<NS>[] valueArray = new EnumItem[size];
    for (int i = 0; i < size; ++i) {
        int currentSize = ByteUtil.bytesHighFirstToInt(bytes, index);
        index += 4;
        EnumItem<NS> item = new EnumItem<NS>();
        for (int j = 0; j < currentSize; ++j) {
            NS NS = NSArray[ByteUtil.bytesHighFirstToInt(bytes, index)];
            index += 4;
            int frequency = ByteUtil.bytesHighFirstToInt(bytes, index);
            index += 4;
            item.labelMap.put(NS, frequency);
        }
        valueArray[i] = item;
    }
    return valueArray;
}
Also used : NS(com.hankcs.hanlp.corpus.tag.NS) EnumItem(com.hankcs.hanlp.corpus.dictionary.item.EnumItem)

Aggregations

EnumItem (com.hankcs.hanlp.corpus.dictionary.item.EnumItem)9 Vertex (com.hankcs.hanlp.seg.common.Vertex)6 NR (com.hankcs.hanlp.corpus.tag.NR)3 NS (com.hankcs.hanlp.corpus.tag.NS)3 NT (com.hankcs.hanlp.corpus.tag.NT)3 LinkedList (java.util.LinkedList)3 Nature (com.hankcs.hanlp.corpus.tag.Nature)1