BlueObelisk / chemicaltagger

ChemicalTagger is a tool for semantic text-mining in chemistry.
Apache License 2.0
36 stars 8 forks source link

Guidance to run chemicaltagger on CLI #6

Closed sathiyabalu89 closed 3 years ago

sathiyabalu89 commented 3 years ago

I was able to execute Chemicaltagger on Eclipse. I exported the project as runnable jar (Chemicaltagger.jar) with "Final_test.java" as main class. The content of the Final_test.java is same as in the readme.md

import uk.ac.cam.ch.wwmm.chemicaltagger.POSContainer;
import uk.ac.cam.ch.wwmm.chemicaltagger.ChemistryPOSTagger;
import uk.ac.cam.ch.wwmm.chemicaltagger.ChemistrySentenceParser;
import uk.ac.cam.ch.wwmm.chemicaltagger.Utils;
import nu.xom.Document;

public class ChemicalTaggerTest {

   public static void main(String[] args) {
      String text = "A solution of 124C (7.0 g, 32.4 mmol) in concentrate H2SO4 " +
                "(9.5 mL) was added to a solution of concentrate H2SO4 (9.5 mL) " +
                "and fuming HNO3 (13 mL) and the mixture was heated at 60°C for " +
                "30 min. After cooling to room temperature, the reaction mixture " +
                "was added to iced 6M solution of NaOH (150 mL) and neutralized " +
                "to pH 6 with 1N NaOH solution. The reaction mixture was extracted " +
                "with dichloromethane (4x100 mL). The combined organic phases were " +
                "dried over Na2SO4, filtered and concentrated to give 124D as a solid.";

      // Calling ChemistryPOSTagger
      POSContainer posContainer = ChemistryPOSTagger.getDefaultInstance().runTaggers(text);

      // Returns a string of TAG TOKEN format (e.g.: DT The NN cat VB sat IN on DT the NN matt)
      // Call ChemistrySentenceParser either by passing the POSContainer or by InputStream
      ChemistrySentenceParser chemistrySentenceParser = new ChemistrySentenceParser(posContainer);

      // Create a parseTree of the tagged input
      chemistrySentenceParser.parseTags();

      // Return an XMLDoc
      Document doc = chemistrySentenceParser.makeXMLDocument();

      Utils.writeXMLToFile(doc,"target/file1.xml");

   }
}

Then, when I run in CLI as "java -jar Chemicaltagger.jar", I get the following error.

image

I tried changing the path in RegexTagger.java to "private String tagFilePath ="resources/uk/ac/cam/ch/wwmm/chemicaltagger/regexTagger/regexTags.txt"; " as the regexTags.txt is in Chemicaltagger/resource folder when I unzipped the jar file. But got the same error.

It would be great if I can get to run Chemicaltagger on CLI. Is it possible to have CLI repo for chemical tagger similar to BlueObelisk/oscar4-cli. Once again thank for the wonderful work.

sathiyabalu89 commented 3 years ago

I was able to download the jar file from https://search.maven.org/artifact/uk.ac.cam.ch.wwmm/chemicalTagger. And i was able to execute the Final_test.java. Thank you.

petermr commented 3 years ago

Thanks, The SLF4J (log4j) error seems to be quite common , e.g. https://mkyong.com/java/log4j2-failed-to-load-class-org-slf4j-impl-staticloggerbinder/

On Tue, Dec 15, 2020 at 6:18 PM sathiyabalu89 notifications@github.com wrote:

I was able to download the jar file from https://search.maven.org/artifact/uk.ac.cam.ch.wwmm/chemicalTagger. And i was able to execute the Final_test.java. Thank you.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BlueObelisk/chemicaltagger/issues/6#issuecomment-745473146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFTCS4E6IVMBEZCZBGGJ7LSU6R7BANCNFSM4U2IFNBA .

-- "I always retain copyright in my papers, and nothing in any contract I sign with any publisher will override that fact. You should do the same".

Peter Murray-Rust Reader Emeritus in Molecular Informatics Yusuf Hamied Department of Chemistry University of Cambridge CB2 1EW, UK +44-1223-336432

mjw99 commented 3 years ago

I am glad you resolved this; but I am not 100% what the cause of it was.

On the point of a CLI example, this is not exactly what you want, but is in the right ball park and may be able to give you some ideas.

Mantas-it commented 3 years ago

Hello, would you be able to help me in understanding how you were able to run Final_test.java ? I seem to be running into the exact same problem. Thank you

JERatDEV commented 3 years ago

The same for me @Mantas-it did you find a solution?