-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1462: Run experiments with Grobid as a potential Cermine repl…
…acement WIP: first version of Grobid wrapper. Not working at the moment due to java class version mismatch requiring the whole IIS to be compiled with java11 or newer.Y
- Loading branch information
1 parent
c04b086
commit 9ed1e44
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ction/src/main/java/eu/dnetlib/iis/wf/metadataextraction/GrobidBasedContentExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package eu.dnetlib.iis.wf.metadataextraction; | ||
|
||
import java.io.File; | ||
import java.util.Collections; | ||
|
||
import org.grobid.core.*; | ||
import org.grobid.core.data.*; | ||
import org.grobid.core.factory.*; | ||
import org.grobid.core.main.GrobidHomeFinder; | ||
import org.grobid.core.main.LibraryLoader; | ||
import org.grobid.core.utilities.*; | ||
import org.grobid.core.engines.Engine; | ||
import org.grobid.core.engines.config.GrobidAnalysisConfig; | ||
|
||
/** | ||
* Simple content extractor relying on Grobid library. | ||
* | ||
* @author mhorst | ||
*/ | ||
public class GrobidBasedContentExtractor { | ||
|
||
private static String grobidHome = "/home/mhorst/grobid-home"; | ||
|
||
public static void initializeGrobid() { | ||
|
||
GrobidHomeFinder grobidHomeFinder = new GrobidHomeFinder(Collections.singletonList(grobidHome)); | ||
GrobidProperties.getInstance(grobidHomeFinder); | ||
|
||
// Load native libraries required for Grobid | ||
LibraryLoader.load(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
String fileLocation = "/home/mhorst/Downloads/HPM-35-1009.pdf"; | ||
|
||
extractMeta(fileLocation); | ||
extractText(fileLocation); | ||
} | ||
|
||
private static void extractMeta(String fileLocation) { | ||
Engine engine = GrobidFactory.getInstance().createEngine(); | ||
// 0 - no consolidation | ||
int consolidate = 0; | ||
try { | ||
BiblioItem result = new BiblioItem(); | ||
engine.processHeader(fileLocation, consolidate, result); | ||
System.out.println("Title: " + result.getTitle()); | ||
System.out.println("Authors: " + result.getAuthors()); | ||
System.out.println("Abstract: " + result.getAbstract()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private static void extractText(String fileLocation) { | ||
Engine engine = GrobidFactory.getInstance().createEngine(); | ||
try { | ||
GrobidAnalysisConfig config = GrobidAnalysisConfig.builder().consolidateHeader(0).build(); | ||
File file = new File(fileLocation); | ||
String fullText = engine.fullTextToTEI(file, config); | ||
System.out.println("Extracted Text: " + fullText); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters