1. Testing out the new sparql query modified to suit v1.1 ontology
2. Made changes to test capturing publication year through different properties (core:year, core:yearMonth, core:date)
This commit is contained in:
parent
ec71544bb6
commit
b231488675
4 changed files with 105 additions and 23 deletions
|
@ -38,10 +38,11 @@ public class QueryConstants {
|
|||
put("wos", "http://vivo.mannlib.cornell.edu/ns/ThomsonWOS/0.1#");
|
||||
put("core", "http://vivoweb.org/ontology/core#");
|
||||
put("vivo", "http://vivo.library.cornell.edu/ns/0.1#");
|
||||
put("j.1", "http://aims.fao.org/aos/geopolitical.owl#");
|
||||
put("j.2", "http://vitro.mannlib.cornell.edu/ns/vitro/public#");
|
||||
|
||||
}};
|
||||
|
||||
|
||||
public static String getSparqlPrefixQuery() {
|
||||
|
||||
StringBuilder prefixSection = new StringBuilder();
|
||||
|
|
|
@ -20,6 +20,8 @@ public class QueryFieldLabels {
|
|||
public static final String DOCUMENT_BLURB = "documentBlurbLit";
|
||||
public static final String DOCUMENT_DESCRIPTION = "documentDescriptionLit";
|
||||
public static final String DOCUMENT_PUBLICATION_YEAR = "publicationYearLit";
|
||||
public static final String DOCUMENT_PUBLICATION_YEAR_MONTH = "publicationYearMonthLit";
|
||||
public static final String DOCUMENT_PUBLICATION_DATE = "publicationDateLit";
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -31,7 +31,6 @@ import edu.cornell.mannlib.vitro.webapp.visualization.valueobjects.Individual;
|
|||
|
||||
|
||||
/**
|
||||
* Very dumb name of the class. change it.
|
||||
* @author cdtank
|
||||
*
|
||||
*/
|
||||
|
@ -57,12 +56,16 @@ public class QueryHandler {
|
|||
" (str(?documentLabel) as ?documentLabelLit) " +
|
||||
" (str(?documentBlurb) as ?documentBlurbLit) " +
|
||||
" (str(?publicationYear) as ?publicationYearLit) " +
|
||||
" (str(?publicationYearMonth) as ?publicationYearMonthLit) " +
|
||||
" (str(?publicationDate) as ?publicationDateLit) " +
|
||||
" (str(?documentDescription) as ?documentDescriptionLit) ";
|
||||
|
||||
private static final String SPARQL_QUERY_COMMON_WHERE_CLAUSE = "" +
|
||||
"?document rdf:type bibo:Document ." +
|
||||
"?document rdfs:label ?documentLabel ." +
|
||||
"OPTIONAL { ?document vivo:publicationYear ?publicationYear } ." +
|
||||
"OPTIONAL { ?document core:year ?publicationYear } ." +
|
||||
"OPTIONAL { ?document core:yearMonth ?publicationYearMonth } ." +
|
||||
"OPTIONAL { ?document core:date ?publicationDate } ." +
|
||||
"OPTIONAL { ?document vitro:moniker ?documentMoniker } ." +
|
||||
"OPTIONAL { ?document vitro:blurb ?documentBlurb } ." +
|
||||
"OPTIONAL { ?document vitro:description ?documentDescription }";
|
||||
|
@ -115,6 +118,16 @@ public class QueryHandler {
|
|||
biboDocument.setPublicationYear(publicationYearNode.toString());
|
||||
}
|
||||
|
||||
RDFNode publicationYearMonthNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_YEAR_MONTH);
|
||||
if (publicationYearMonthNode != null) {
|
||||
biboDocument.setPublicationYearMonth(publicationYearMonthNode.toString());
|
||||
}
|
||||
|
||||
RDFNode publicationDateNode = solution.get(QueryFieldLabels.DOCUMENT_PUBLICATION_DATE);
|
||||
if (publicationDateNode != null) {
|
||||
biboDocument.setPublicationDate(publicationDateNode.toString());
|
||||
}
|
||||
|
||||
/*
|
||||
* Since we are getting publication count for just one author at a time we need
|
||||
* to create only one "Individual" instance. We test against the null for "author" to
|
||||
|
@ -168,11 +181,12 @@ public class QueryHandler {
|
|||
+ SPARQL_QUERY_COMMON_SELECT_CLAUSE
|
||||
+ "(str(<" + queryURI + ">) as ?authPersonLit) "
|
||||
+ "WHERE { "
|
||||
+ "<" + queryURI + "> rdf:type foaf:Person ; vivo:authorOf ?document ; rdfs:label ?authorLabel. "
|
||||
+ "<" + queryURI + "> rdf:type foaf:Person ; rdfs:label ?authorLabel ; core:authorInAuthorship ?authorshipNode . "
|
||||
+ " ?authorshipNode rdf:type core:Authorship ; core:linkedInformationResource ?document . "
|
||||
+ SPARQL_QUERY_COMMON_WHERE_CLAUSE
|
||||
+ "}";
|
||||
|
||||
log.debug("SPARQL query for person pub count -> \n" + sparqlQuery);
|
||||
System.out.println("SPARQL query for person pub count -> \n" + sparqlQuery);
|
||||
|
||||
return sparqlQuery;
|
||||
}
|
||||
|
@ -196,8 +210,6 @@ public class QueryHandler {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ResultSet resultSet = executeQuery(this.queryParam,
|
||||
this.resultFormatParam,
|
||||
this.rdfResultFormatParam,
|
||||
|
@ -222,11 +234,16 @@ public class QueryHandler {
|
|||
/*
|
||||
* Increment the count because there is an entry already available for
|
||||
* that particular year.
|
||||
*
|
||||
* I am pushing the logic to check for validity of year in "getPublicationYear" itself
|
||||
* because,
|
||||
* 1. We will be using getPub... multiple times & this will save us duplication of code
|
||||
* 2. If we change the logic of validity of a pub year we would not have to make changes
|
||||
* all throughout the codebase.
|
||||
* 3. We are asking for a publication year & we should get a proper one or NOT at all.
|
||||
* */
|
||||
String publicationYear;
|
||||
if (curr.getPublicationYear() != null
|
||||
&& curr.getPublicationYear().length() != 0
|
||||
&& curr.getPublicationYear().trim().length() != 0) {
|
||||
if (curr.getPublicationYear() != null) {
|
||||
publicationYear = curr.getPublicationYear();
|
||||
} else {
|
||||
publicationYear = curr.getParsedPublicationYear();
|
||||
|
|
|
@ -8,6 +8,10 @@ import java.util.regex.Pattern;
|
|||
|
||||
import edu.cornell.mannlib.vitro.webapp.visualization.constants.VOConstants;
|
||||
|
||||
/**
|
||||
* @author cdtank
|
||||
*
|
||||
*/
|
||||
public class BiboDocument extends Individual{
|
||||
|
||||
public static final int MINIMUM_PUBLICATION_YEAR = 1800;
|
||||
|
@ -17,6 +21,8 @@ public class BiboDocument extends Individual{
|
|||
private String documentBlurb;
|
||||
private String documentDescription;
|
||||
private String publicationYear;
|
||||
private String publicationYearMonth;
|
||||
private String publicationDate;
|
||||
private String parsedPublicationYear = VOConstants.DEFAULT_PUBLICATION_YEAR;
|
||||
|
||||
public BiboDocument(String documentURL) {
|
||||
|
@ -50,9 +56,9 @@ public class BiboDocument extends Individual{
|
|||
public void setDocumentBlurb(String documentBlurb) {
|
||||
this.documentBlurb = documentBlurb;
|
||||
|
||||
if (documentBlurb != null) {
|
||||
this.setParsedPublicationYear(parsePublicationYear(documentBlurb));
|
||||
}
|
||||
// if (documentBlurb != null) {
|
||||
// this.setParsedPublicationYear(parsePublicationYear(documentBlurb));
|
||||
// }
|
||||
}
|
||||
|
||||
private String parsePublicationYear(String documentBlurb) {
|
||||
|
@ -96,15 +102,38 @@ public class BiboDocument extends Individual{
|
|||
this.documentDescription = documentDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called when there is no usable core:year value found
|
||||
* for the bibo:Document. It will first check & parse core:yearMonth failing
|
||||
* which it will try core:date
|
||||
* @return
|
||||
*/
|
||||
public String getParsedPublicationYear() {
|
||||
|
||||
/*
|
||||
* Only the
|
||||
* We are assuming that core:yearMonth has "YYYY-MM" format. This is based
|
||||
* off of http://www.w3.org/TR/xmlschema-2/#gYearMonth , which is what
|
||||
* core:yearMonth points to internally.
|
||||
* */
|
||||
private void setParsedPublicationYear(String parsedPublicationYear) {
|
||||
this.parsedPublicationYear = parsedPublicationYear;
|
||||
if (publicationYearMonth != null
|
||||
&& publicationYearMonth.length() >= 4
|
||||
&& isValidPublicationYear(publicationYearMonth.substring(0, 4))) {
|
||||
|
||||
return publicationYearMonth.substring(0, 4);
|
||||
|
||||
}
|
||||
|
||||
public String getParsedPublicationYear() {
|
||||
return parsedPublicationYear;
|
||||
if (publicationDate != null
|
||||
&& publicationDate.length() >= 4
|
||||
&& isValidPublicationYear(publicationDate.substring(0, 4))) {
|
||||
|
||||
return publicationDate.substring(0, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
* If all else fails return default unknown year identifier
|
||||
* */
|
||||
return VOConstants.DEFAULT_PUBLICATION_YEAR;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -112,11 +141,44 @@ public class BiboDocument extends Individual{
|
|||
* then use the parsedPublicationYear.
|
||||
* */
|
||||
public String getPublicationYear() {
|
||||
if (publicationYear != null && isValidPublicationYear(publicationYear)) {
|
||||
return publicationYear;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setPublicationYear(String publicationYear) {
|
||||
this.publicationYear = publicationYear;
|
||||
}
|
||||
|
||||
public String getPublicationYearMonth() {
|
||||
return publicationYearMonth;
|
||||
}
|
||||
|
||||
public void setPublicationYearMonth(String publicationYearMonth) {
|
||||
this.publicationYearMonth = publicationYearMonth;
|
||||
}
|
||||
|
||||
public String getPublicationDate() {
|
||||
return publicationDate;
|
||||
}
|
||||
|
||||
public void setPublicationDate(String publicationDate) {
|
||||
this.publicationDate = publicationDate;
|
||||
}
|
||||
|
||||
private boolean isValidPublicationYear(String testPublicationYear) {
|
||||
|
||||
if (testPublicationYear.length() != 0
|
||||
&& testPublicationYear.trim().length() == 4
|
||||
&& testPublicationYear.matches("\\d+")
|
||||
&& Integer.parseInt(testPublicationYear) >= MINIMUM_PUBLICATION_YEAR) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue