-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add funder consolidation with crossref rest api
- Loading branch information
Showing
4 changed files
with
133 additions
and
2 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
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
79 changes: 79 additions & 0 deletions
79
grobid-core/src/main/java/org/grobid/core/utilities/crossref/FunderDeserializer.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,79 @@ | ||
package org.grobid.core.utilities.crossref; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.grobid.core.data.BiblioItem; | ||
import org.grobid.core.data.Person; | ||
import org.grobid.core.data.Date; | ||
import org.grobid.core.data.Funder; | ||
import org.grobid.core.utilities.TextUtilities; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
|
||
/** | ||
* Convert a JSON Funder model - from a glutton or crossref response - to a Funder object | ||
* (understandable by this stupid GROBID). | ||
* | ||
* Input JSON format is from the REST API query. For example: | ||
* https://api.crossref.org/funders?query=agence+nationale+de+la+recherche | ||
* | ||
* For better data (Crossref funder registry one), we can then use the data API: | ||
* http://data.crossref.org/fundingdata/funder/10.13039/501100001665 | ||
* | ||
*/ | ||
public class FunderDeserializer extends CrossrefDeserializer<Funder> { | ||
|
||
@Override | ||
protected Funder deserializeOneItem(JsonNode item) { | ||
Funder funder = null; | ||
String type = null; // the crossref type of the item, see http://api.crossref.org/types | ||
|
||
if (item.isObject()) { | ||
funder = new Funder(); | ||
//System.out.println(item.toString()); | ||
|
||
JsonNode locationNode = item.get("location"); | ||
if (locationNode != null && (!locationNode.isMissingNode()) ) { | ||
String location = locationNode.asText(); | ||
funder.setCountry(location); | ||
} | ||
|
||
// we always have a uri field, and we can get the DOI from this... | ||
// surprisingly no DOI field ! | ||
JsonNode uriNode = item.get("uri"); | ||
if (uriNode != null && (!uriNode.isMissingNode()) ) { | ||
String uri = uriNode.asText(); | ||
if (uri != null) | ||
uri = uri.replace("http://dx.doi.org/", ""); | ||
funder.setDoi(uri); | ||
} | ||
|
||
JsonNode nameNode = item.get("name"); | ||
if (nameNode != null && (!nameNode.isMissingNode()) ) { | ||
String name = nameNode.asText(); | ||
funder.setFullName(name); | ||
} | ||
|
||
|
||
JsonNode altNamesNode = item.get("alt-names"); | ||
if (altNamesNode != null && (!altNamesNode.isMissingNode()) && | ||
altNamesNode.isArray() && (((ArrayNode)altNamesNode).size() > 0)) { | ||
|
||
// here we just keep an acronym form - better names with lang info via the data API | ||
for(int i=0; i <((ArrayNode)altNamesNode).size(); i++) { | ||
String altName = ((ArrayNode)altNamesNode).get(i).asText(); | ||
if (TextUtilities.isAllUpperCase(altName) && altName.length()<10) { | ||
funder.setAbbreviatedName(altName); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
//System.out.println(funder.toTEI()); | ||
} | ||
|
||
return funder; | ||
} | ||
} |
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