-1

I have this method which returns an arrayList tokens :

public static String[] Tokenize(String input) throws InvalidFormatException, IOException {
    InputStream is = new FileInputStream("en-token.bin");    
    TokenizerModel model = new TokenizerModel(is);   
    Tokenizer tokenizer = new TokenizerME(model);    
    String tokens[] = tokenizer.tokenize(input);     
    for (String a : tokens)
        System.out.println(a);   
    is.close();
    return tokens;
}

I want these tokens to be used in another method:

public static void findName(String[] input) throws IOException {
    InputStream is = new FileInputStream("en-ner-person.bin");   
    TokenNameFinderModel model = new TokenNameFinderModel(is);
    is.close();  
    NameFinderME nameFinder = new NameFinderME(model);   
    Span nameSpans[] = nameFinder.find(input);   
    for(Span s: nameSpans)
        System.out.println(s.toString());           
}

Also, how can I use this tokens arrayList in another class something like,

public class Main{
    public static void main( String[] args) throws Exception
    {
        Anotherclass.Tokenize(input);
        Anotherclass.findName(tokens);

    }
}

I'm unable to figure this out! Please help me.

Thanks a ton!

Draken
  • 3,134
  • 13
  • 34
  • 54
smoothsipai
  • 43
  • 10

3 Answers3

1

Just use this:

Anotherclass.findName(Anotherclass.Tokenize(input));
  • But it is not giving any output of the findName method. why is that? – smoothsipai May 11 '16 at 08:08
  • Is there a way I can use tokens[] in the findName method itself? – smoothsipai May 11 '16 at 08:10
  • You can change the return type of findName from void to Span Array i.e Span[] and then you can use that array and make a for loop in main method do whatever you want to do with it. –  May 11 '16 at 09:44
1

You have to re-use your 1st method result into the 2nd one.

public class Main{
     public static void main( String[] args) throws Exception
     {
         String[] tokens = Anotherclass.Tokenize(input);
         Anotherclass.findName(tokens);

     }
}

You still have to figure out where does your input variable comes from.

0

you created static method so you can call those method by Class name like

String[] SAMPLEARRAY = YOURCLASSNAME.Tokenize(String_ARRAY);
KhAn SaAb
  • 5,248
  • 5
  • 31
  • 52