转换MultiLabelDataset<字符串,字符串>番石榴Multimap之印刷/检验 [英] convert MultiLabelDataset<String, String> to Guava Multimap for printing / examining

查看:115
本文介绍了转换MultiLabelDataset<字符串,字符串>番石榴Multimap之印刷/检验的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的程序工作:

public static void main(String[] args) throws Exception
{
    String input = args[0];

    InputStream is = new BufferedInputStream( new FileInputStream( input ) );

    toMultiLabelDataset(is);
    is.close();
}

public static MultiLabelDataset<String, String> toMultiLabelDataset(InputStream is) throws IOException
{
    List<RelationAndMentions> relations = toRelations(is, true);
    MultiLabelDataset<String, String> dataset = toDataset(relations);

    return dataset;
}

正如你可以看到它利用形式的数据结构 MultiLabelDataset&LT;字符串,字符串&GT; ,我想打印兽的内容在一个人intelligabe形式。根据我的previous搜索我可能可以使用Apache字符串utils的或谷歌番石榴库,是这样吗?我会如何打算的?

As you can see it utilizes a data structure of the form MultiLabelDataset<String, String>, I want to print the contents of that beast in a human intelligabe form. According to my previous searching I can likely use apache string utils or google guava library, is that right? How would I go about going that?

我的猜测是,那里有这些库中的等价数据STRUC,一种采用&LT;字符串,字符串&GT; ,我只需要确定那是什么,复制字符串,字符串&GT; 然后打印 MultiLabelDataset&LT的内容?那是合理的?

My guess would be that theres an equivalent data struc in those libraries, one that takes <String, String>, I just need to determine what that is, copy the contents of MultiLabelDataset<String, String> and then print? Is that reasonable?

    Multimap<String, String> result = HashMultimap.create();
    for (String key : ((MultiLabelDataset) dataset).items) 
    {
        for (String value : dataset.getLabels()) 
        {
            result.put(key, value);
        }
    }

^不喜欢这样。

^not like that.

推荐答案

假设它是这个<一个href=\"http://nlp.stanford.edu/software/tmt/tmt-0.4/api/edu/stanford/nlp/tmt/data/MultiLabelDataset.html\"相对=nofollow> MultiLabelDataset ,那么它类似于番石榴的<一个href=\"http://docs.guava-libraries.google$c$c.com/git/javadoc/com/google/common/collect/Multimap.html\"相对=nofollow> Multimap之,你可以很容易地将其转换。但是,这种转换将是既不比直接转换为字符串更简单,也更聪明。唯一的好处是,以后你可以用具有许多有用的方法,并与其他Java类合作以及一个健全的Java类的工作。

Assuming it's this MultiLabelDataset, then it's similar to Guava's Multimap and you can convert it easily. However, this conversion will be neither simpler nor smarter than a direct conversion to a String. The only advantage would be that thereafter you can work with a sane Java class having many useful method and working well together with other Java classes.

整个转换出现像往常一样,但你需要的东西迭代的钥匙。假设只有实现LabeledLDADataset,很容易:

The whole conversion goes like always, but you need something to iterate the keys. Assuming the only implementation is LabeledLDADataset, it's easy:

Multimap<String, String> toMultimap(MultiLabelDataset<String, String> dataset) {
    Multimap<String, String> result = HashMultimap.create();
    for (Item key : ((LabeledLDADataset) dataset).items()) {
        result.putAll(key.toString(), dataset.getLabels(key));
    }
    return result;
}

这篇关于转换MultiLabelDataset&LT;字符串,字符串&GT;番石榴Multimap之印刷/检验的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆