org.grobid.core.utilities.GrobidProperties Java Examples

The following examples show how to use org.grobid.core.utilities.GrobidProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utilities.java    From entity-fishing with Apache License 2.0 6 votes vote down vote up
public static void initGrobid() {
	ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

	try {
        NerdConfig conf = mapper.readValue(new File("data/config/mention.yaml"), NerdConfig.class);
		String pGrobidHome = conf.getGrobidHome();

		GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Arrays.asList(pGrobidHome));
       	GrobidProperties.getInstance(grobidHomeFinder);
           LibraryLoader.load();
		LOGGER.info(">>>>>>>> GROBID_HOME="+GrobidProperties.get_GROBID_HOME_PATH());
	}
	catch(Exception e) {
		throw new NerdException("Fail to initalise the grobid-ner component.", e);
	}
}
 
Example #2
Source File: GrobidPDFProcessor.java    From science-result-extractor with Apache License 2.0 5 votes vote down vote up
private GrobidPDFProcessor() throws IOException, Exception {
        prop = new Properties();
        prop.load(new FileReader("config.properties"));
        grobidHome = prop.getProperty("pGrobidHome");
        grobidProperties = prop.getProperty("pGrobidProperties");
        GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Arrays.asList(grobidHome));
        GrobidProperties.getInstance(grobidHomeFinder);
//        System.out.println(">>>>>>>> GROBID_HOME="+GrobidProperties.get_GROBID_HOME_PATH());
        engine = GrobidFactory.getInstance().createEngine();
        parsers = new EngineParsers();
        gson = new Gson();
        cloner = new Cloner();
    }
 
Example #3
Source File: NERFrenchTrainer.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
/**
 * Command line execution.
 *
 * @param args Command line arguments.
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    GrobidProperties.getInstance();
    NERFrenchTrainer trainer = new NERFrenchTrainer();

    AbstractTrainer.runTraining(trainer);
    System.out.println(AbstractTrainer.runEvaluation(trainer));

    System.exit(0);
}
 
Example #4
Source File: CoNNLNERTrainer.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
/**
 * Command line execution.
 *
 * @param args Command line arguments.
 */
public static void main(String[] args) {
    GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Arrays.asList("../grobid-home"));
    GrobidProperties.getInstance(grobidHomeFinder);

    CoNNLNERTrainer trainer = new CoNNLNERTrainer();

    trainer.trainCoNLL(true);
    //trainer.evalCoNLL("eng.testa");
    trainer.evalCoNLL("eng.testb");
}
 
Example #5
Source File: NEREvaluation.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
protected final File getTempEvaluationDataPath() {
    try {
        return File.createTempFile(model.getModelName(), ".test", GrobidProperties.getTempPath());
    } catch (IOException e) {
        throw new RuntimeException("Unable to create a temporary evaluation file for model: " + model);
    }
}
 
Example #6
Source File: NEREvaluation.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
/**
 * Command line execution.
 *
 * @param args Command line arguments.
 */
public static void main(String[] args) {
    final GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Arrays.asList("../../grobid-home", "../grobid-home"));
    GrobidProperties.getInstance(grobidHomeFinder);

    NEREvaluation eval = new NEREvaluation();

    // CoNLL evaluation
    System.out.println(eval.evaluate_reuters());
}
 
Example #7
Source File: SenseTrainer.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
/**
 * Standard evaluation via the the usual Grobid evaluation framework.
 */
public String evaluate() {
    File evalDataF = GrobidProperties.getInstance().getEvalCorpusPath(
            new File(new File("resources").getAbsolutePath()), model);

    File tmpEvalPath = getTempEvaluationDataPath();
    createCRFPPData(evalDataF, tmpEvalPath);

    return EvaluationUtilities.evaluateStandard(tmpEvalPath.getAbsolutePath(), getTagger()).toString();
}
 
Example #8
Source File: SenseTrainer.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
/**
 * Command line execution.
 *
 * @param args Command line arguments.
 */
public static void main(String[] args) {
    final GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Arrays.asList("../../grobid-home", "../grobid-home"));
    GrobidProperties.getInstance(grobidHomeFinder);

    Trainer trainer = new SenseTrainer();
    AbstractTrainer.runTraining(trainer);
    //AbstractTrainer.runEvaluation(trainer);
}
 
Example #9
Source File: NERTrainer.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
/**
 * Command line execution.
 *
 * @param args Command line arguments.
 */
public static void main(String[] args) {
    final GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Arrays.asList("../../grobid-home", "../grobid-home"));
    GrobidProperties.getInstance(grobidHomeFinder);
    NERTrainer trainer = new NERTrainer();

    AbstractTrainer.runTraining(trainer);
    System.out.println(AbstractTrainer.runEvaluation(trainer));

    System.exit(0);
}
 
Example #10
Source File: NERMain.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
/**
 * Init process with the provided grobid-home
 *
 * @param grobidHome
 */
protected static void initProcess(String grobidHome) {
    try {
        final GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Arrays.asList(grobidHome));
        grobidHomeFinder.findGrobidHomeOrFail();
        GrobidProperties.getInstance(grobidHomeFinder);
        LibraryLoader.load();
    } catch (final Exception exp) {
        System.err.println("Grobid initialisation failed: " + exp);
    }
}
 
Example #11
Source File: NERMain.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
/**
 * Init process with the default value of the grobid home
 */
protected static void initProcess() {
    try {
        LibraryLoader.load();
    } catch (final Exception exp) {
        System.err.println("Grobid initialisation failed: " + exp);
    }
    GrobidProperties.getInstance();
}
 
Example #12
Source File: NERLexicon.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
private NERLexicon() {

        String pathSenseDescriptions = GrobidProperties.getGrobidHomePath() + "/lexicon/senses/descriptions.txt";
        // read the Wordnet descriptions
        try {
            BufferedReader bufReader = new BufferedReader(
                    new InputStreamReader(new FileInputStream(pathSenseDescriptions)));
            String line;
            while ((line = bufReader.readLine()) != null) {
                if (line.trim().length() == 0) {
                    continue;
                }
                if (line.trim().startsWith("#")) {
                    // this is a comment
                    continue;
                }
                String[] parts = line.trim().split("\t");
                if (parts.length != 2) {
                    continue;
                }
                descriptions.put(parts[0], parts[1]);
            }
            bufReader.close();
        } catch (IOException e) {
            throw new GrobidException("Error reading word sense dfescriptions file.", e);
        }
    }
 
Example #13
Source File: EngineMockTest.java    From grobid-ner with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initInitialContext() throws Exception {
    final GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Arrays.asList("../../grobid-home", "../grobid-home"));
    grobidHomeFinder.findGrobidHomeOrFail();

    GrobidProperties.getInstance(grobidHomeFinder);
    engine = GrobidFactory.getInstance().createEngine();
}
 
Example #14
Source File: NEREvaluation.java    From grobid-ner with Apache License 2.0 4 votes vote down vote up
public NEREvaluation() {
    GrobidProperties.getInstance();
    model = GrobidModels.ENTITIES_NER;
    loadAdditionalProperties();
}
 
Example #15
Source File: NEREvaluation.java    From grobid-ner with Apache License 2.0 4 votes vote down vote up
/**
 * Evaluation based on the CoNLL-2003 shared task NER gold corpus, English set.
 * see http://www.cnts.ua.ac.be/conll2003/ner/.
 */
public String evaluate_reuters() {
    long start = System.currentTimeMillis();
    StringBuilder report = new StringBuilder();
    try {
        GrobidFactory.getInstance();
        NERParsers parsers = new NERParsers();

        File evalDataF = GrobidProperties.getInstance().getEvalCorpusPath(
                new File(new File("resources").getAbsolutePath()), model);

        File tmpEvalPath = getTempEvaluationDataPath();

        report.append("Eval. path: " + tmpEvalPath.getPath() + "\n");

        // There are three set that we can exploit testa, testb and the training sets.
        // However the training set should be used to reimforce the learning.
        File evalA = new File(conllPath + "/eng.testa");
        File evalB = new File(conllPath + "/eng.testb");
        File evalTrain = new File(conllPath + "/eng.train");

        if (!evalTrain.exists()) {
            throw new GrobidException(
                    "Cannot start evaluation, because corpus resource path for CoNLL file " +
                            " is not correctly set : " + evalDataF.getPath() + "/eng.train");
        }
        report.append(evaluate_reutersSet(parsers, evalTrain, tmpEvalPath));

        if (!evalA.exists()) {
            throw new GrobidException(
                    "Cannot start evaluation, because corpus resource path for CoNLL file " +
                            " is not correctly set : " + evalDataF.getPath() + "/eng.testa");
        }
        report.append(evaluate_reutersSet(parsers, evalA, tmpEvalPath));

        if (!evalB.exists()) {
            throw new GrobidException(
                    "Cannot start evaluation, because corpus resource path for CoNLL file " +
                            " is not correctly set : " + evalDataF.getPath() + "/eng.testb");
        }
        report.append(evaluate_reutersSet(parsers, evalB, tmpEvalPath));
    } catch (Exception e) {
        throw new GrobidException("An exception occured while running Grobid Reuters evaluation.", e);
    }
    long end = System.currentTimeMillis();
    report.append("processed in " + (end - start) / 1000 + " s.");

    return report.toString();
}