convert MultiLabelDataset<String, String> to Guava Multimap for printing / examining

允我心安 提交于 2019-12-02 06:00:57

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.

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!