Skip to content

Commit

Permalink
propagate maximum parallel requests to grobid
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Oct 22, 2024
1 parent 450e5f2 commit 0206b5c
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/main/java/org/grobid/service/GrobidEngineInitialiser.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package org.grobid.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.collect.ImmutableList;
import org.grobid.core.lexicon.DatastetLexicon;
import org.grobid.core.main.GrobidHomeFinder;
import org.grobid.core.main.LibraryLoader;
import org.grobid.core.utilities.GrobidProperties;
import org.grobid.core.engines.tagging.GrobidCRFEngine;
import org.grobid.core.lexicon.DatastetLexicon;
import org.grobid.service.configuration.DatastetServiceConfiguration;
import org.grobid.core.utilities.DatastetConfiguration;
import org.grobid.core.utilities.GrobidConfig;
import org.grobid.core.utilities.GrobidConfig.ModelParameters;

import java.io.*;

import org.grobid.core.utilities.GrobidProperties;
import org.grobid.service.configuration.DatastetServiceConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.lang.reflect.Field;

@Singleton
public class GrobidEngineInitialiser {
Expand All @@ -36,7 +34,7 @@ public GrobidEngineInitialiser(DatastetServiceConfiguration configuration) {
try {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
datastetConfiguration = mapper.readValue(new File("resources/config/config.yml").getAbsoluteFile(), DatastetConfiguration.class);
} catch(Exception e) {
} catch (Exception e) {
LOGGER.error("The config file does not appear valid, see resources/config/config.yml", e);
datastetConfiguration = null;
}
Expand All @@ -47,6 +45,18 @@ public GrobidEngineInitialiser(DatastetServiceConfiguration configuration) {
for (ModelParameters model : datastetConfiguration.getModels())
GrobidProperties.getInstance().addModel(model);
}

Class<?> clazz = null; // if you know class name dynamically i.e. at runtime
try {
clazz = Class.forName("org.grobid.core.utilities.GrobidProperties");
Field field = clazz.getDeclaredField("grobidConfig");
field.setAccessible(true);
GrobidConfig grobidConfig = (GrobidConfig) field.get("grobidConfig");
grobidConfig.grobid.concurrency = configuration.getMaxParallelRequests();
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
LOGGER.error("Invalid operation when hacking the GrobidProperties", e);
}

LibraryLoader.load();
}
}

0 comments on commit 0206b5c

Please sign in to comment.