[VIVO 1647] - Improve AgrovocService.java using diamond operator (#97)
* Use diamond operator on ArrayList declarations * Use the diamond operator to simpplify declarations Resolves: https://jira.duraspace.org/browse/VIVO-1647
This commit is contained in:
parent
9580863285
commit
fda5e83102
1 changed files with 8 additions and 8 deletions
|
@ -63,7 +63,7 @@ public class AgrovocService implements ExternalConceptService {
|
||||||
protected final String conceptSkosMosURL = conceptSkosMosBase + "data?";
|
protected final String conceptSkosMosURL = conceptSkosMosBase + "data?";
|
||||||
@Override
|
@Override
|
||||||
public List<Concept> getConcepts(String term) throws Exception {
|
public List<Concept> getConcepts(String term) throws Exception {
|
||||||
List<Concept> conceptList = new ArrayList<Concept>();
|
List<Concept> conceptList = new ArrayList<>();
|
||||||
|
|
||||||
//For the RDF webservices mechanism, utilize the following
|
//For the RDF webservices mechanism, utilize the following
|
||||||
/*
|
/*
|
||||||
|
@ -86,7 +86,7 @@ public class AgrovocService implements ExternalConceptService {
|
||||||
return conceptList;
|
return conceptList;
|
||||||
int conceptCounter = 0;
|
int conceptCounter = 0;
|
||||||
|
|
||||||
HashSet<String> encounteredURI = new HashSet<String>();
|
HashSet<String> encounteredURI = new HashSet<>();
|
||||||
|
|
||||||
// Loop through each of these URIs and load using the SKOSManager
|
// Loop through each of these URIs and load using the SKOSManager
|
||||||
for (String conceptUri : conceptUris) {
|
for (String conceptUri : conceptUris) {
|
||||||
|
@ -185,7 +185,7 @@ public class AgrovocService implements ExternalConceptService {
|
||||||
public List<Concept> getConceptsByURIWithSparql(String uri)
|
public List<Concept> getConceptsByURIWithSparql(String uri)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
// deprecating this method...just return an empty list
|
// deprecating this method...just return an empty list
|
||||||
List<Concept> conceptList = new ArrayList<Concept>();
|
List<Concept> conceptList = new ArrayList<>();
|
||||||
return conceptList;
|
return conceptList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ public class AgrovocService implements ExternalConceptService {
|
||||||
// When utilizing the getTermExpansion method, will get a list of URIs back
|
// When utilizing the getTermExpansion method, will get a list of URIs back
|
||||||
// and not just one URI
|
// and not just one URI
|
||||||
protected List<String> getConceptURIsListFromRDF(String rdf) {
|
protected List<String> getConceptURIsListFromRDF(String rdf) {
|
||||||
List<String> conceptUris = new ArrayList<String>();
|
List<String> conceptUris = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Document doc = XMLUtils.parse(rdf);
|
Document doc = XMLUtils.parse(rdf);
|
||||||
NodeList nodes = doc.getElementsByTagName("skos:Concept");
|
NodeList nodes = doc.getElementsByTagName("skos:Concept");
|
||||||
|
@ -262,21 +262,21 @@ public class AgrovocService implements ExternalConceptService {
|
||||||
+ "> rdfs:comment ?description . \n"
|
+ "> rdfs:comment ?description . \n"
|
||||||
+ "FILTER (LANG(?description)='en' ) \n" + "}";
|
+ "FILTER (LANG(?description)='en' ) \n" + "}";
|
||||||
// System.out.println(qs);
|
// System.out.println(qs);
|
||||||
List<HashMap> resultList = new ArrayList<HashMap>();
|
List<HashMap> resultList = new ArrayList<>();
|
||||||
QueryExecution qexec = null;
|
QueryExecution qexec = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Query query = QueryFactory.create(qs);
|
Query query = QueryFactory.create(qs);
|
||||||
qexec = QueryExecutionFactory.sparqlService(this.dbpedia_endpoint, query);
|
qexec = QueryExecutionFactory.sparqlService(this.dbpedia_endpoint, query);
|
||||||
qexec.setTimeout(5000, TimeUnit.MILLISECONDS);
|
qexec.setTimeout(5000, TimeUnit.MILLISECONDS);
|
||||||
resultList = new ArrayList<HashMap>();
|
resultList = new ArrayList<>();
|
||||||
ResultSet resultSet = qexec.execSelect();
|
ResultSet resultSet = qexec.execSelect();
|
||||||
int resultSetSize = 0;
|
int resultSetSize = 0;
|
||||||
while (resultSet.hasNext()) {
|
while (resultSet.hasNext()) {
|
||||||
resultSetSize++;
|
resultSetSize++;
|
||||||
QuerySolution solution = resultSet.nextSolution();
|
QuerySolution solution = resultSet.nextSolution();
|
||||||
Iterator varnames = solution.varNames();
|
Iterator varnames = solution.varNames();
|
||||||
HashMap<String, String> hm = new HashMap<String, String>();
|
HashMap<String, String> hm = new HashMap<>();
|
||||||
while (varnames.hasNext()) {
|
while (varnames.hasNext()) {
|
||||||
String name = (String) varnames.next();
|
String name = (String) varnames.next();
|
||||||
RDFNode rdfnode = solution.get(name);
|
RDFNode rdfnode = solution.get(name);
|
||||||
|
@ -374,7 +374,7 @@ public class AgrovocService implements ExternalConceptService {
|
||||||
|
|
||||||
//JSON-LD array
|
//JSON-LD array
|
||||||
private List<String> getConceptURIsListFromSkosMosResult(String results) {
|
private List<String> getConceptURIsListFromSkosMosResult(String results) {
|
||||||
List<String> conceptURIs = new ArrayList<String>();
|
List<String> conceptURIs = new ArrayList<>();
|
||||||
ObjectNode json = (ObjectNode) JacksonUtils.parseJson(results);
|
ObjectNode json = (ObjectNode) JacksonUtils.parseJson(results);
|
||||||
//Format should be: { ..."results":["uri":uri...]
|
//Format should be: { ..."results":["uri":uri...]
|
||||||
if (json.has("results")) {
|
if (json.has("results")) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue