[VIVO-1306] fixing LCSH lookup (#45)
This commit is contained in:
parent
8ee3e1e74f
commit
da8943e64a
1 changed files with 23 additions and 29 deletions
|
@ -49,7 +49,7 @@ public class LCSHService implements ExternalConceptService {
|
||||||
String results = null;
|
String results = null;
|
||||||
String dataUrl = baseUri + "?q=" + URLEncoder.encode(term, "UTF-8")
|
String dataUrl = baseUri + "?q=" + URLEncoder.encode(term, "UTF-8")
|
||||||
+ "&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
|
+ "&q=cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2Fsubjects"
|
||||||
+ "&format=XML";
|
+ "&format=atom";
|
||||||
log.debug("dataURL " + dataUrl);
|
log.debug("dataURL " + dataUrl);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -81,7 +81,7 @@ public class LCSHService implements ExternalConceptService {
|
||||||
return conceptList;
|
return conceptList;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Results are in json format (atom) - atom entries need to be extracted
|
// Results are in XML format (atom) - atom entries need to be extracted
|
||||||
// retrieve the URIs and get the SKOS version of the entry, getting broader
|
// retrieve the URIs and get the SKOS version of the entry, getting broader
|
||||||
// and narrower terms as applicable as well as any description (skos:note)
|
// and narrower terms as applicable as well as any description (skos:note)
|
||||||
// that might exist
|
// that might exist
|
||||||
|
@ -99,7 +99,7 @@ public class LCSHService implements ExternalConceptService {
|
||||||
//This is the URL for retrieving the concept - the pattern is http://id.loc.gov/authorities/subjects/sh85014203.skos.rdf
|
//This is the URL for retrieving the concept - the pattern is http://id.loc.gov/authorities/subjects/sh85014203.skos.rdf
|
||||||
//This is not the URI itself which would be http://id.loc.gov/authorities/subjects/sh85014203
|
//This is not the URI itself which would be http://id.loc.gov/authorities/subjects/sh85014203
|
||||||
String conceptURLString = getSKOSURL(uri);
|
String conceptURLString = getSKOSURL(uri);
|
||||||
String baseConceptURI = getConceptURI(uri);
|
String baseConceptURI = uri;
|
||||||
URL conceptURL = null;
|
URL conceptURL = null;
|
||||||
try {
|
try {
|
||||||
conceptURL = new URL(conceptURLString);
|
conceptURL = new URL(conceptURLString);
|
||||||
|
@ -154,23 +154,12 @@ public class LCSHService implements ExternalConceptService {
|
||||||
|
|
||||||
|
|
||||||
private String getSKOSURL(String uri) {
|
private String getSKOSURL(String uri) {
|
||||||
// Strip .xml at the end and replace with .skos.rdf
|
String skosURI = uri + skosSuffix;
|
||||||
String skosURI = uri;
|
|
||||||
if (uri.endsWith(".xml")) {
|
return skosURI;
|
||||||
skosURI = uri.substring(0, uri.length() - 4);
|
|
||||||
skosURI += skosSuffix;
|
|
||||||
}
|
|
||||||
return hostUri + skosURI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Given the URI from the xml, get just the base URI
|
|
||||||
private String getConceptURI(String uri) {
|
|
||||||
String skosURI = uri;
|
|
||||||
if (uri.endsWith(".xml")) {
|
|
||||||
skosURI = uri.substring(0, uri.length() - 4);
|
|
||||||
}
|
|
||||||
return hostUri + skosURI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getConceptURISFromJSON(String results) {
|
public List<String> getConceptURISFromJSON(String results) {
|
||||||
List<String> uris = new ArrayList<String>();
|
List<String> uris = new ArrayList<String>();
|
||||||
|
@ -192,14 +181,25 @@ public class LCSHService implements ExternalConceptService {
|
||||||
String conceptUri = new String();
|
String conceptUri = new String();
|
||||||
try {
|
try {
|
||||||
Document doc = XMLUtils.parse(rdf);
|
Document doc = XMLUtils.parse(rdf);
|
||||||
NodeList nodes = doc.getElementsByTagName("search:result");
|
NodeList nodes = doc.getElementsByTagName("entry");
|
||||||
int len = nodes.getLength();
|
int len = nodes.getLength();
|
||||||
int i;
|
int i, j;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
Node node = nodes.item(i);
|
Node node = nodes.item(i);
|
||||||
NamedNodeMap attrs = node.getAttributes();
|
NodeList childNodes = node.getChildNodes();
|
||||||
Attr idAttr = (Attr) attrs.getNamedItem("uri");
|
for(j = 0; j < childNodes.getLength(); j++) {
|
||||||
conceptUri = idAttr.getTextContent();
|
Node childNode = childNodes.item(j);
|
||||||
|
if(childNode.getNodeName().equals("link")) {
|
||||||
|
NamedNodeMap attrs = childNode.getAttributes();
|
||||||
|
Attr hrefAttr = (Attr) attrs.getNamedItem("href");
|
||||||
|
//if type doesn't exist, this is the direct URL without extension
|
||||||
|
if((hrefAttr != null) && ((Attr)attrs.getNamedItem("type") == null)) {
|
||||||
|
conceptUri = hrefAttr.getTextContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.debug("concept uri is " + conceptUri);
|
log.debug("concept uri is " + conceptUri);
|
||||||
uris.add(conceptUri);
|
uris.add(conceptUri);
|
||||||
}
|
}
|
||||||
|
@ -250,10 +250,4 @@ public class LCSHService implements ExternalConceptService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue