How can I resolve the issue when finding location in a sentence using Apache OpenNLP










0















package com.example.dell.apacheopennlp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.namefind.TokenNameFinderModel;
import opennlp.tools.tokenize.TokenizerME;
import opennlp.tools.tokenize.TokenizerModel;
import opennlp.tools.util.Span;
public class apacheOpenNLP extends AppCompatActivity

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_apache_open_nlp);
final TextView txt = (TextView) findViewById (R.id.txtView);

InputStream inputStream = null;
TokenizerModel tokenModel =null;
try
inputStream = getAssets().open("en-token.bin");
tokenModel = new TokenizerModel (inputStream);
inputStream.close();
catch (IOException e)
e.printStackTrace();
txt.setText (e.toString ()+" inside catch of token");


if(tokenModel!=null)
TokenizerME tokenizer = new TokenizerME (tokenModel);
String paragraph = "Tutorialspoint is located in Hyderabad";
String tokens = tokenizer.tokenize (paragraph);
InputStream locationInputStream=null;
TokenNameFinderModel locationModel = null;

try

locationInputStream = getAssets ( ).open ("en-ner-location.bin");
locationModel = new TokenNameFinderModel (locationInputStream);

catch (IOException e)
e.printStackTrace ( );
txt.setText (e.toString ()+" inside catch of location");


if (locationModel != null)
NameFinderME nameFinder = new NameFinderME (locationModel);
Span nameSpans = nameFinder.find (tokens);

String result = null;
for (Span s : nameSpans)
//result= s.toString()+" "+tokens[s.getStart()];
result += s.toString ( );
txt.setText (result);

else
// txt.setText ("Location model is empty");






I am using the apache OpenNLP to extract the location in a sentence. I have debug the code and found that after NameFinderME nameFinder = new NameFinderME (locationModel); the android app crash showing a message "The app has stopped working"
How can I resolve this issue?










share|improve this question
























  • it throws java.lang.IllegalStateException:java.xml.parsers.ParserConfigurationException

    – Sara
    Nov 15 '18 at 13:26
















0















package com.example.dell.apacheopennlp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.namefind.TokenNameFinderModel;
import opennlp.tools.tokenize.TokenizerME;
import opennlp.tools.tokenize.TokenizerModel;
import opennlp.tools.util.Span;
public class apacheOpenNLP extends AppCompatActivity

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_apache_open_nlp);
final TextView txt = (TextView) findViewById (R.id.txtView);

InputStream inputStream = null;
TokenizerModel tokenModel =null;
try
inputStream = getAssets().open("en-token.bin");
tokenModel = new TokenizerModel (inputStream);
inputStream.close();
catch (IOException e)
e.printStackTrace();
txt.setText (e.toString ()+" inside catch of token");


if(tokenModel!=null)
TokenizerME tokenizer = new TokenizerME (tokenModel);
String paragraph = "Tutorialspoint is located in Hyderabad";
String tokens = tokenizer.tokenize (paragraph);
InputStream locationInputStream=null;
TokenNameFinderModel locationModel = null;

try

locationInputStream = getAssets ( ).open ("en-ner-location.bin");
locationModel = new TokenNameFinderModel (locationInputStream);

catch (IOException e)
e.printStackTrace ( );
txt.setText (e.toString ()+" inside catch of location");


if (locationModel != null)
NameFinderME nameFinder = new NameFinderME (locationModel);
Span nameSpans = nameFinder.find (tokens);

String result = null;
for (Span s : nameSpans)
//result= s.toString()+" "+tokens[s.getStart()];
result += s.toString ( );
txt.setText (result);

else
// txt.setText ("Location model is empty");






I am using the apache OpenNLP to extract the location in a sentence. I have debug the code and found that after NameFinderME nameFinder = new NameFinderME (locationModel); the android app crash showing a message "The app has stopped working"
How can I resolve this issue?










share|improve this question
























  • it throws java.lang.IllegalStateException:java.xml.parsers.ParserConfigurationException

    – Sara
    Nov 15 '18 at 13:26














0












0








0








package com.example.dell.apacheopennlp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.namefind.TokenNameFinderModel;
import opennlp.tools.tokenize.TokenizerME;
import opennlp.tools.tokenize.TokenizerModel;
import opennlp.tools.util.Span;
public class apacheOpenNLP extends AppCompatActivity

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_apache_open_nlp);
final TextView txt = (TextView) findViewById (R.id.txtView);

InputStream inputStream = null;
TokenizerModel tokenModel =null;
try
inputStream = getAssets().open("en-token.bin");
tokenModel = new TokenizerModel (inputStream);
inputStream.close();
catch (IOException e)
e.printStackTrace();
txt.setText (e.toString ()+" inside catch of token");


if(tokenModel!=null)
TokenizerME tokenizer = new TokenizerME (tokenModel);
String paragraph = "Tutorialspoint is located in Hyderabad";
String tokens = tokenizer.tokenize (paragraph);
InputStream locationInputStream=null;
TokenNameFinderModel locationModel = null;

try

locationInputStream = getAssets ( ).open ("en-ner-location.bin");
locationModel = new TokenNameFinderModel (locationInputStream);

catch (IOException e)
e.printStackTrace ( );
txt.setText (e.toString ()+" inside catch of location");


if (locationModel != null)
NameFinderME nameFinder = new NameFinderME (locationModel);
Span nameSpans = nameFinder.find (tokens);

String result = null;
for (Span s : nameSpans)
//result= s.toString()+" "+tokens[s.getStart()];
result += s.toString ( );
txt.setText (result);

else
// txt.setText ("Location model is empty");






I am using the apache OpenNLP to extract the location in a sentence. I have debug the code and found that after NameFinderME nameFinder = new NameFinderME (locationModel); the android app crash showing a message "The app has stopped working"
How can I resolve this issue?










share|improve this question
















package com.example.dell.apacheopennlp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.namefind.TokenNameFinderModel;
import opennlp.tools.tokenize.TokenizerME;
import opennlp.tools.tokenize.TokenizerModel;
import opennlp.tools.util.Span;
public class apacheOpenNLP extends AppCompatActivity

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_apache_open_nlp);
final TextView txt = (TextView) findViewById (R.id.txtView);

InputStream inputStream = null;
TokenizerModel tokenModel =null;
try
inputStream = getAssets().open("en-token.bin");
tokenModel = new TokenizerModel (inputStream);
inputStream.close();
catch (IOException e)
e.printStackTrace();
txt.setText (e.toString ()+" inside catch of token");


if(tokenModel!=null)
TokenizerME tokenizer = new TokenizerME (tokenModel);
String paragraph = "Tutorialspoint is located in Hyderabad";
String tokens = tokenizer.tokenize (paragraph);
InputStream locationInputStream=null;
TokenNameFinderModel locationModel = null;

try

locationInputStream = getAssets ( ).open ("en-ner-location.bin");
locationModel = new TokenNameFinderModel (locationInputStream);

catch (IOException e)
e.printStackTrace ( );
txt.setText (e.toString ()+" inside catch of location");


if (locationModel != null)
NameFinderME nameFinder = new NameFinderME (locationModel);
Span nameSpans = nameFinder.find (tokens);

String result = null;
for (Span s : nameSpans)
//result= s.toString()+" "+tokens[s.getStart()];
result += s.toString ( );
txt.setText (result);

else
// txt.setText ("Location model is empty");






I am using the apache OpenNLP to extract the location in a sentence. I have debug the code and found that after NameFinderME nameFinder = new NameFinderME (locationModel); the android app crash showing a message "The app has stopped working"
How can I resolve this issue?







java apache android-studio-3.0 opennlp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 17:51







Sara

















asked Nov 14 '18 at 16:50









SaraSara

84




84












  • it throws java.lang.IllegalStateException:java.xml.parsers.ParserConfigurationException

    – Sara
    Nov 15 '18 at 13:26


















  • it throws java.lang.IllegalStateException:java.xml.parsers.ParserConfigurationException

    – Sara
    Nov 15 '18 at 13:26

















it throws java.lang.IllegalStateException:java.xml.parsers.ParserConfigurationException

– Sara
Nov 15 '18 at 13:26






it throws java.lang.IllegalStateException:java.xml.parsers.ParserConfigurationException

– Sara
Nov 15 '18 at 13:26













1 Answer
1






active

oldest

votes


















0














Can you try to change the nameFinder to be declared as TokenNameFinder interface type?



Just try to replace



NameFinderME nameFinder = null


with



TokenNameFinder nameFinder = null


Rest all should be same.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305138%2fhow-can-i-resolve-the-issue-when-finding-location-in-a-sentence-using-apache-ope%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Can you try to change the nameFinder to be declared as TokenNameFinder interface type?



    Just try to replace



    NameFinderME nameFinder = null


    with



    TokenNameFinder nameFinder = null


    Rest all should be same.






    share|improve this answer



























      0














      Can you try to change the nameFinder to be declared as TokenNameFinder interface type?



      Just try to replace



      NameFinderME nameFinder = null


      with



      TokenNameFinder nameFinder = null


      Rest all should be same.






      share|improve this answer

























        0












        0








        0







        Can you try to change the nameFinder to be declared as TokenNameFinder interface type?



        Just try to replace



        NameFinderME nameFinder = null


        with



        TokenNameFinder nameFinder = null


        Rest all should be same.






        share|improve this answer













        Can you try to change the nameFinder to be declared as TokenNameFinder interface type?



        Just try to replace



        NameFinderME nameFinder = null


        with



        TokenNameFinder nameFinder = null


        Rest all should be same.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 4 '18 at 11:41









        Shivam GandhiShivam Gandhi

        113




        113





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305138%2fhow-can-i-resolve-the-issue-when-finding-location-in-a-sentence-using-apache-ope%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Peter Parker: The Spectacular Spider-Man #308