jcrfsuite
jcrfsuite copied to clipboard
About tagging input string
Hi, How to tag input string? This library only works with input and output files. But I need to insert string and get predict labels.
I also need to predict string data...
@uugan hi,I write a simple code, input feature String List and model path ,return predict result
public static List<List<Pair<String, Double>>> predict(List<String> texts,String modelPath){ CrfTagger crfTagger = new CrfTagger(modelPath); List<List<Pair<String, Double>>> taggedSentences = new ArrayList(); List<ItemSequence> xseqs = new ArrayList(); ItemSequence xseq = new ItemSequence(); for (String text :texts){ String [] fields = text.split("\t"); Item item = new Item(); for (int i = 0; i < fields.length; ++ i){ String field = fields[i]; item.add(new Attribute(field)); } xseq.add(item); } xseqs.add(xseq); Iterator var = xseqs.iterator(); while(var.hasNext()) { ItemSequence xseq1 = (ItemSequence)var.next(); taggedSentences.add(crfTagger.tag(xseq1)); } return taggedSentences; }