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

Running CoreNLP server without internet (offline) #1356

Open
mercurial-moon opened this issue May 5, 2023 · 10 comments
Open

Running CoreNLP server without internet (offline) #1356

mercurial-moon opened this issue May 5, 2023 · 10 comments

Comments

@mercurial-moon
Copy link

I have read this question https://github.com/stanfordnlp/CoreNLP/issues/384 but it doesn't give a definitive answer.

I can run the server on a windows machine with the command line

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000

the server starts and i can connect to it with a web browser by entering 127.0.0.1:9000 into the browser url bar.

But when inspecting the request in browser dev tool it seems the javascript and other resource files are loading from online sources
line standford.edu, cloudflare, jquery, bootstrap etc.

This causes the webpage to break.
image

also the submit button doesn't work.

Is there a workaround to this to get it to work without an internet connection?

@AngledLuffa
Copy link
Contributor

We've never given any consideration to packaging all the assets so the server can work without an internet connection, but it's probably something you can do.

@mercurial-moon
Copy link
Author

Hi, yes i tried doing that but I didn't know where to start? I don't see any folder with css or js files and the url's to access these may be coded into the jar, I'm not sure if there is any external config file to change those paths.
Could you please provide any pointers about where to start digging in.

@AngledLuffa
Copy link
Contributor

Probably corenlp-brat.html? It will require rebuilding the jar to make any such edits take effect. The jar program should assist with that (jar -xvf, jar -cvf or jar -u, etc)

@mercurial-moon
Copy link
Author

mercurial-moon commented May 5, 2023

Ok thanks for that info, I see some more things being reference in here

StanfordCoreNLPServer

I see that the html file you linked (corenlp-brat.html) has the links that we need to modify, i'll try that and see where it goes' will ping back again if i get stuck. thanks.

@mercurial-moon
Copy link
Author

ok, so i tried doing this, i renamed the stanford-corenlp-4.5.3.jar to zip and then extracted it and found the corenlp-brat.html inside it.
Then downnloaded all the resources and saved it in the same dir as corenlp-brat.html
then changed all the links in corenlp-brat.html to take it from local

image

then i repackaged the zip to jar and restarted the server but it still can't find the resources.
Am I missing something.

@AngledLuffa
Copy link
Contributor

AngledLuffa commented May 6, 2023 via email

@mercurial-moon
Copy link
Author

mercurial-moon commented May 6, 2023

I appreciate your help
At this link i see some code where the java server is handling 2 files internal
Java web server

The relevant lines are

 withAuth(server.createContext(uriContext+"/corenlp-brat.js", new FileHandler("edu/stanford/nlp/pipeline/demo/corenlp-brat.js", "application/javascript")), basicAuth);
      
withAuth(server.createContext(uriContext+"/corenlp-brat.cs", new FileHandler("edu/stanford/nlp/pipeline/demo/corenlp-brat.css", "text/css")), basicAuth);

Do you think that add the other resources to this file will do the job?
I was trying to avoid compling the jar, but it seems the only way at the moment.

@AngledLuffa
Copy link
Contributor

AngledLuffa commented May 6, 2023 via email

@mercurial-moon
Copy link
Author

mercurial-moon commented May 20, 2023

So I finally got it to work without compiling the jar,
Steps as under for version 4.5.3

  1. Rename the stanford-corenlp-4.5.3.jar to zip (your jar may be different based on the version of Stanford NLP)
  2. Extract the zip to some folder and go to this path inside the zip edu\stanford\nlp\pipeline\demo
  3. There you need to edit 2 files corenlp-brat.html and corenlp-brat.js
  4. These files refer to number of external resources that first need to be downloaded and stored on your computer.
  5. Note down the external link from each file and and paste it in the browser and download the file, make sure you maintain the relative path.
  6. Rename each link in the files and modify it to http://localhost/... instead of the external link.
  7. Repackage all the files\folders of the zip and rename to jar.
  8. Overwrite the original stanford-corenlp-4.5.3.jar with the new modified jar.
  9. Copy the downloaded resources to a folder, these need to be served by a local webserver that runs on your pc. Use any server like xampp, caddy, redbean etc. I chose caddy.
  10. Put all the resources in a folder and keep it next to the caddy executable. Run caddy with caddy file-server --root "path to folder where caddy resides"
  11. Fire up core nlp server with java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
  12. Open a browser and visit localhost:9000, and if all goes well you should be able to see the main page of Core Nlp, similar to the online demo

@AngledLuffa
Copy link
Contributor

AngledLuffa commented May 20, 2023 via email

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