Skip to content

Commit

Permalink
Revert "adding REST API for the sentence segmentation"
Browse files Browse the repository at this point in the history
This reverts commit 534b3bd
  • Loading branch information
lfoppiano committed Nov 10, 2020
1 parent 63fba67 commit dbeff71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 68 deletions.
Expand Up @@ -702,21 +702,6 @@ public Response annotatePDFPatentCitation(
return restProcessFiles.annotateCitationPatentPDF(inputStream, consol, includeRaw);
}

@Path("/segmentSentence")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_XML)
@POST
public Response segmentSentenceText_post(@FormDataParam(INPUT) String text) {
return restProcessString.segmentSentences(text);
}

@Path("/segmentSentence")
@Produces(MediaType.APPLICATION_XML)
@GET
public Response segmentSentenceText_get(@QueryParam(INPUT) String text) {
return restProcessString.segmentSentences(text);
}

public void setRestProcessFiles(GrobidRestProcessFiles restProcessFiles) {
this.restProcessFiles = restProcessFiles;
}
Expand Down
Expand Up @@ -20,21 +20,17 @@
import org.grobid.core.engines.Engine;
import org.grobid.core.engines.config.GrobidAnalysisConfig;
import org.grobid.core.factory.GrobidPoolingFactory;
import org.grobid.core.utilities.OffsetPosition;
import org.grobid.core.utilities.SentenceUtilities;
import org.grobid.service.util.BibTexMediaType;
import org.grobid.service.util.ExpectedResponseType;
import org.grobid.service.util.GrobidRestUtils;
//import org.grobid.service.util.GrobidServiceProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.commons.collections4.CollectionUtils.isEmpty;

/**
*
*
* Web services consuming String
*
*
*/
@Singleton
public class GrobidRestProcessString {
Expand All @@ -46,41 +42,9 @@ public GrobidRestProcessString() {

}

public Response segmentSentences(String text) {
Response response = null;
String retVal = null;
Engine engine = null;
try {
engine = Engine.getEngine(true);
SentenceUtilities instance = SentenceUtilities.getInstance();
List<OffsetPosition> offsetPositions = instance.runSentenceDetection(text);

String outputText = instance.getXml(text, offsetPositions);
if (isEmpty(offsetPositions)) {
response = Response.status(Status.NO_CONTENT).build();
} else {
response = Response.status(Status.OK)
.entity(outputText)
.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN + "; charset=UTF-8")
.build();
}
} catch (NoSuchElementException nseExp) {
LOGGER.error("Could not get an engine from the pool within configured time. Sending service unavailable.");
response = Response.status(Status.SERVICE_UNAVAILABLE).build();
} catch (Exception e) {
LOGGER.error("An unexpected exception occurs. ", e);
response = Response.status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
if (engine != null) {
GrobidPoolingFactory.returnEngine(engine);
}
}
return response;
}

/**
* Parse a raw date and return the corresponding normalized date.
*
*
* @param date raw date string
* @return a response object containing the structured xml representation of
* the date
Expand All @@ -92,7 +56,7 @@ public Response processDate(String date) {
Engine engine = null;
try {
LOGGER.debug(">> set raw date for stateless service'...");

engine = Engine.getEngine(true);
date = date.replaceAll("\\n", " ").replaceAll("\\t", " ");
List<Date> dates = engine.processDate(date);
Expand Down Expand Up @@ -131,7 +95,7 @@ public Response processDate(String date) {
/**
* Parse a raw sequence of names from a header section and return the
* corresponding normalized authors.
*
*
* @param names string of the raw sequence of header authors
* @return a response object containing the structured xml representation of
* the authors
Expand All @@ -147,7 +111,7 @@ public Response processNamesHeader(String names) {
engine = Engine.getEngine(true);
names = names.replaceAll("\\n", " ").replaceAll("\\t", " ");
List<Person> authors = engine.processAuthorsHeader(names);

if (authors != null) {
for(Person person : authors) {
if (retVal == null) {
Expand Down Expand Up @@ -184,7 +148,7 @@ public Response processNamesHeader(String names) {
/**
* Parse a raw sequence of names from a header section and return the
* corresponding normalized authors.
*
*
* @param names string of the raw sequence of header authors.
* @return a response object containing the structured xml representation of
* the authors
Expand All @@ -200,7 +164,7 @@ public Response processNamesCitation(String names) {
engine = Engine.getEngine(true);
names = names.replaceAll("\\n", " ").replaceAll("\\t", " ");
List<Person> authors = engine.processAuthorsCitation(names);

if (authors != null) {
for(Person person : authors) {
if (retVal == null) {
Expand Down Expand Up @@ -236,7 +200,7 @@ public Response processNamesCitation(String names) {
/**
* Parse a raw sequence of affiliations and return the corresponding
* normalized affiliations with address.
*
*
* @param affiliation of the raw sequence of affiliation+address
* @return a response object containing the structured xml representation of
* the affiliation
Expand All @@ -253,13 +217,13 @@ public Response processAffiliations(String affiliation) {
affiliation = affiliation.replaceAll("\\t", " ");
List<Affiliation> affiliationList = engine.processAffiliation(affiliation);

if (affiliationList != null) {
if (affiliationList != null) {
for(Affiliation affi : affiliationList) {
if (retVal == null) {
retVal = "";
}
retVal += affi.toTEI();
}
}
}
if (GrobidRestUtils.isResultNullOrEmpty(retVal)) {
response = Response.status(Status.NO_CONTENT).build();
Expand Down Expand Up @@ -288,7 +252,7 @@ public Response processAffiliations(String affiliation) {
/**
* Parse a raw sequence of affiliations and return the corresponding
* normalized affiliations with address.
*
*
* @param citation
* string of the raw sequence of affiliation+address
* @param expectedResponseType
Expand All @@ -304,7 +268,7 @@ public Response processCitation(String citation, GrobidAnalysisConfig config, Ex
engine = Engine.getEngine(true);
//citation = citation.replaceAll("\\n", " ").replaceAll("\\t", " ");
BiblioItem biblioItem = engine.processRawReference(citation, config.getConsolidateCitations());

if (biblioItem == null) {
response = Response.status(Status.NO_CONTENT).build();
} else if (expectedResponseType == ExpectedResponseType.BIBTEX) {
Expand Down Expand Up @@ -335,12 +299,12 @@ public Response processCitation(String citation, GrobidAnalysisConfig config, Ex

/**
* Parse a patent description text and return the extracted and parsed patent and non-patent citations.
*
*
* @param text
* string of the patent description text to be processed
* @param consolidate
* consolidation parameter for the non patent extracted and parsed citation
*
*
* @return a response object containing the structured xml representation of
* the affiliation
*/
Expand All @@ -350,9 +314,9 @@ public Response processCitationPatentTXT(String text, int consolidate, boolean i
Engine engine = null;
try {
engine = Engine.getEngine(true);

List<PatentItem> patents = new ArrayList<PatentItem>();
List<BibDataSet> articles = new ArrayList<BibDataSet>();
List<BibDataSet> articles = new ArrayList<BibDataSet>();
text = text.replaceAll("\\t", " ");
String result = engine.processAllCitationsInPatent(text, articles, patents, consolidate, includeRawCitations);

Expand Down

0 comments on commit dbeff71

Please sign in to comment.