jcrfsuite icon indicating copy to clipboard operation
jcrfsuite copied to clipboard

About tagging input string

Open uugan opened this issue 7 years ago • 2 comments

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.

uugan avatar Sep 02 '17 10:09 uugan

I also need to predict string data...

Coffeexiudou avatar May 23 '18 13:05 Coffeexiudou

@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; }

Coffeexiudou avatar May 24 '18 03:05 Coffeexiudou