Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

About tagging input string #12

Open
uugan opened this issue Sep 2, 2017 · 2 comments
Open

About tagging input string #12

uugan opened this issue Sep 2, 2017 · 2 comments

Comments

@uugan
Copy link

uugan commented Sep 2, 2017

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 uugan changed the title Training and testing data file for NER About tagging input string Sep 4, 2017
@Coffeexiudou
Copy link

I also need to predict string data...

@Coffeexiudou
Copy link

@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 texts,String modelPath){
CrfTagger crfTagger = new CrfTagger(modelPath);
List<List<Pair<String, Double>>> taggedSentences = new ArrayList();
List 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;
}

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

No branches or pull requests

2 participants