Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

srl库有问题,无法进行语义角色标注 #19

Open
6295685 opened this issue Oct 9, 2016 · 6 comments
Open

srl库有问题,无法进行语义角色标注 #19

6295685 opened this issue Oct 9, 2016 · 6 comments

Comments

@6295685
Copy link

6295685 commented Oct 9, 2016

@carfly @Oneplus @jiangfeng1124 @endyul

import java.util.ArrayList;
import java.util.List;
import edu.hit.ir.ltp4j.*;

public class Ltp4jTest {

public static void main(String[] args) {
    // 分词
    if (Segmentor.create("/Users/mac/Documents/ltp-3.3.2/ltp_data/cws.model") < 0) {
        System.err.println("load failed");
        return;
    }

    String sent = "国务院总理李克强调研上海外高桥时提出,支持上海积极探索新机制。";
    List<String> words = new ArrayList<String>();
    int size = Segmentor.segment(sent, words);

    for (int i = 0; i < size; i++) {
        System.out.print(words.get(i));
        if (i == size - 1) {
            System.out.println();
        } else {
            System.out.print(" | ");
        }
    }

    Segmentor.release();

    // 词性标注
    if (Postagger.create("/Users/mac/Documents/ltp-3.3.2/ltp_data/pos.model") < 0) {
        System.err.println("load failed");
        return;
    }

    List<String> postags = new ArrayList<String>();
    size = Postagger.postag(words, postags);

    for (int i = 0; i < size; i++) {
        System.out.print(words.get(i) + "/" + postags.get(i));
        if (i == size - 1) {
            System.out.println();
        } else {
            System.out.print(" | ");
        }
    }

    Postagger.release();

    // 命名实体识别
    if (NER.create("/Users/mac/Documents/ltp-3.3.2/ltp_data/ner.model") < 0) {
        System.err.println("load failed");
        return;
    }

    List<String> ners = new ArrayList<String>();
    NER.recognize(words, postags, ners);

    for (int i = 0; i < ners.size(); i++) {
        if (!"O".equals(ners.get(i)))
            System.out.println(ners.get(i));
    }

    NER.release();

    // 依存句法分析
    if (Parser.create("/Users/mac/Documents/ltp-3.3.2/ltp_data/parser.model") < 0) {
        System.err.println("load failed");
        return;
    }

    List<Integer> heads = new ArrayList<Integer>();
    List<String> deprels = new ArrayList<String>();
    size = Parser.parse(words, postags, heads, deprels);

    for (int i = 0; i < size; i++) {
        System.out.print(heads.get(i) + ":" + deprels.get(i));
        if (i == size - 1) {
            System.out.println();
        } else {
            System.out.print(" ");
        }
    }

    Parser.release();

    // 语义角色标注
    SRL.create("/Users/mac/Documents/ltp-3.3.2/ltp_data/srl");

    List<Pair<Integer, List<Pair<String, Pair<Integer, Integer>>>>> srls = new ArrayList<Pair<Integer, List<Pair<String, Pair<Integer, Integer>>>>>();
    SRL.srl(words, postags, ners, heads, deprels, srls);

    System.out.println(words);
    System.out.println(postags);
    System.out.println(ners);
    System.out.println(heads);
    System.out.println(deprels);
    System.out.println(srls.size());

    for (int i = 0; i < srls.size(); ++i) {
        System.out.println(srls.get(i).first + ":");
        for (int j = 0; j < srls.get(i).second.size(); ++j) {
            System.out.println("   tpye = " + srls.get(i).second.get(j).first + " beg = "
                    + srls.get(i).second.get(j).second.first + " end = " + srls.get(i).second.get(j).second.second);
        }
    }

    SRL.release();
}

}

@6295685
Copy link
Author

6295685 commented Oct 9, 2016

在语义角色标注的程序段没有任何结果输出。程序运行结果如下:

国务院 | 总理 | 李克强 | 调研 | 上海 | 外高桥 | 时 | 提出 | , | 支持 | 上海 | 积极 | 探索 | 新 | 机制 | 。
国务院/ni | 总理/n | 李克强/nh | 调研/v | 上海/ns | 外高桥/ns | 时/n | 提出/v | ,/wp | 支持/v | 上海/ns | 积极/a | 探索/v | 新/a | 机制/n | 。/wp
S-Ni
S-Nh
B-Ns
E-Ns
S-Ns
2:ATT 3:ATT 4:SBV 7:ATT 6:ATT 4:VOB 8:ADV 0:HED 8:WP 8:COO 13:SBV 13:ADV 10:VOB 15:ATT 13:VOB 8:WP

@carfly
Copy link
Member

carfly commented Oct 9, 2016

谢谢指出,我们会尽快解决。

祝好

On Sun, Oct 9, 2016 at 8:37 AM Xiang Lee notifications@github.com wrote:

在语义角色标注的程序段没有任何结果输出。程序运行结果如下:

国务院 | 总理 | 李克强 | 调研 | 上海 | 外高桥 | 时 | 提出 | , | 支持 | 上海 | 积极 | 探索 | 新 | 机制 |

国务院/ni | 总理/n | 李克强/nh | 调研/v | 上海/ns | 外高桥/ns | 时/n | 提出/v | ,/wp | 支持/v
| 上海/ns | 积极/a | 探索/v | 新/a | 机制/n | 。/wp
S-Ni
S-Nh
B-Ns
E-Ns
S-Ns
2:ATT 3:ATT 4:SBV 7:ATT 6:ATT 4:VOB 8:ADV 0:HED 8:WP 8:COO 13:SBV 13:ADV
10:VOB 15:ATT 13:VOB 8:WP


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#19 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAComJQ-bB8_HAK0M2u9JWN5xExRYuOcks5qyDc3gaJpZM4KR3Ue
.

@6295685
Copy link
Author

6295685 commented Oct 11, 2016

@carfly
老师,您好!请问这个问题解决了吗?
另外,语义依存分析Java什么时候能提供api呢?
谢谢您的帮助!

@carfly
Copy link
Member

carfly commented Oct 12, 2016

@endyul 看一下这个问题?

@6295685
Copy link
Author

6295685 commented Oct 21, 2016

@carfly @Oneplus @jiangfeng1124 @endyul
请问,解决不了吗?

@jinpeigen
Copy link

您好,请问这个问题解决了么,我用最新的3.4.0一样没有任何结果输出

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants