VIVO-112 and VIVO-298

This commit is contained in:
tworrall 2013-09-18 17:01:26 -04:00
parent c5d0bc21e8
commit 3d527acce9
5 changed files with 139 additions and 81 deletions

View file

@ -10,6 +10,7 @@
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?subclass
?authorship
@ -41,7 +42,8 @@
OPTIONAL { ?infoResource core:publisher ?publisherObj .
?publisherObj rdfs:label ?publisher
}
OPTIONAL { ?infoResource core:editor ?editorObj .
OPTIONAL { ?infoResource core:relatedBy ?editorship .
?editorObj core:relatedBy ?editorship .
?editorObj rdfs:label ?editor
}
OPTIONAL { ?infoResource core:partOf ?partOfObj .
@ -118,6 +120,7 @@
PREFIX core: <http://vivoweb.org/ontology/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bibo: <http://purl.org/ontology/bibo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT {
?subject ?property ?authorship .
?authorship ?authorshipProperty ?authorshipValue .
@ -125,7 +128,10 @@
?infoResource ?infoResourceProperty ?infoResourceValue .
?infoResource bibo:reproducedIn ?appearsInObj .
?infoResource core:publisher ?publisherObj .
?infoResource core:editor ?editorObj .
?infoResource core:relatedBy ?editorship .
?editorship a core:Editorship .
?editorship core:relates ?editorObj .
?editorObj a foaf:Person .
?infoResource core:partOf ?partOfObj .
?appearsInObj rdfs:label ?appearsIn .
?publisherObj rdfs:label ?publisher .
@ -159,7 +165,8 @@
} UNION {
?subject ?property ?authorship .
?authorship core:relates ?infoResource .
?infoResource core:editor ?editorObj .
?infoResource core:relatedBy ?editorship .
?editorship core:relates ?editorObj .
?editorObj rdfs:label ?editor
} UNION {
?subject ?property ?authorship .

View file

@ -17,7 +17,7 @@
WHERE {
?subject ?property ?authorship .
?authorship a core:Authorship
OPTIONAL { ?authorship core:authorRank ?rank }
OPTIONAL { ?authorship core:rank ?rank }
OPTIONAL { ?authorship core:relates ?person .
?person a foaf:Person .
?person rdfs:label ?personName

View file

@ -8,12 +8,16 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.XSD;
@ -22,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator;
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.PublicationHasAuthorValidator;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeIntervalValidationVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
@ -334,97 +339,115 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
public void addFormSpecificData(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
HashMap<String, Object> formSpecificData = new HashMap<String, Object>();
//Get the existing authorships
formSpecificData.put("existingAuthorInfo", getExistingAuthorships(vreq));
formSpecificData.put("newRank", getMaxRank(vreq) + 1);
formSpecificData.put("rankPredicate", authorRankPredicate);
formSpecificData.put("existingAuthorInfo", getExistingAuthorships(editConfiguration.getSubjectUri(), vreq));
formSpecificData.put("newRank", getMaxRank(editConfiguration.getSubjectUri(), vreq) + 1);
formSpecificData.put("rankPredicate", "http://vivoweb.org/ontology/core#rank");
editConfiguration.setFormSpecificData(formSpecificData);
}
private List<AuthorshipInfo> getExistingAuthorships(VitroRequest vreq) {
Individual infoResource = EditConfigurationUtils.getSubjectIndividual(vreq);
List<Individual> authorships = infoResource.getRelatedIndividuals(
EditConfigurationUtils.getPredicateUri(vreq));
//TODO: Check if sorted correctly
log.debug("authorships = " + authorships);
sortAuthorshipIndividuals(authorships);
return getAuthorshipInfo(authorships);
}
/*
private static String AUTHORSHIPS_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#> \n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
+ "SELECT ?authorshipURI (afn:localname(?authorshipURI) AS ?authorshipName) ?authorURI ?authorName \n"
+ "SELECT ?authorshipURI (afn:localname(?authorshipURI) AS ?authorshipName) ?authorURI ?authorName ?rank \n"
+ "WHERE { \n"
+ "?subject core:relatedBy ?authorshipURI . \n"
+ "?authorshipURI a core:Authorship . \n"
+ "?authorshipURI core:relates ?authorURI . \n"
+ "?authorURI a foaf:Person . \n"
+ "?authorURI rdfs:label ?authorName \n"
+ "}";
+ "OPTIONAL { ?authorURI rdfs:label ?authorName } \n"
+ "OPTIONAL { ?authorshipURI core:rank ?rank } \n"
+ "} ORDER BY ?rank";
private List<Map<String, String>> getExistingAuthorships(String subjectUri, VitroRequest vreq) {
private List<AuthorshipInfo> getExistingAuthorships(String subjectUri, VitroRequest vreq) {
String queryStr = QueryUtils.subUriForQueryVar(this.getAuthorshipsQuery(), "subject", subjectUri);
log.debug("Query string is: " + queryStr);
List<Map<String, String>> authorshipss = new ArrayList<Map<String, String>>();
List<Map<String, String>> authorships = new ArrayList<Map<String, String>>();
try {
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
RDFNode node = soln.get("link");
RDFNode node = soln.get("authorshipURI");
if (node.isURIResource()) {
webpages.add(QueryUtils.querySolutionToStringValueMap(soln));
authorships.add(QueryUtils.querySolutionToStringValueMap(soln));
}
}
} catch (Exception e) {
log.error(e, e);
}
log.debug("webpages = " + webpages);
return webpages;
}
*/
private List<AuthorshipInfo> getAuthorshipInfo(
List<Individual> authorships) {
List<AuthorshipInfo> info = new ArrayList<AuthorshipInfo>();
for ( Individual authorship : authorships ) {
String authorshipUri = authorship.getURI();
String authorshipName = authorship.getName();
String authorUri = "";
String authorName = "";
Individual author = authorship.getRelatedIndividual(linkedAuthorPredicate);
if(author != null) {
authorUri = author.getURI();
authorName = author.getName();
}
AuthorshipInfo aaInfo = new AuthorshipInfo(authorshipUri, authorshipName, authorUri, authorName);
info.add(aaInfo);
}
return info;
log.debug("authorships = " + authorships);
return getAuthorshipInfo(authorships);
}
private int getMaxRank(VitroRequest vreq) {
Individual infoResource = EditConfigurationUtils.getSubjectIndividual(vreq);
List<Individual> authorships = infoResource.getRelatedIndividuals(
EditConfigurationUtils.getPredicateUri(vreq));
sortAuthorshipIndividuals(authorships);
int maxRank = 0;
for(Individual authorship: authorships) {
DataPropertyStatement rankStmt = authorship.getDataPropertyStatement(authorRankPredicate);
if (rankStmt != null) {
maxRank = Integer.parseInt(rankStmt.getData());
private static String MAX_RANK_QUERY = ""
+ "PREFIX core: <http://vivoweb.org/ontology/core#> \n"
+ "SELECT DISTINCT ?rank WHERE { \n"
+ " ?subject core:relatedBy ?authorship . \n"
+ " ?authorship a core:Authorship . \n"
+ " ?authorship core:rank ?rank .\n"
+ "} ORDER BY DESC(?rank) LIMIT 1";
private int getMaxRank(String subjectUri, VitroRequest vreq) {
int maxRank = 0; // default value
String queryStr = QueryUtils.subUriForQueryVar(this.getMaxRankQueryStr(), "subject", subjectUri);
log.debug("maxRank query string is: " + queryStr);
try {
ResultSet results = QueryUtils.getQueryResults(queryStr, vreq);
if (results != null && results.hasNext()) { // there is at most one result
QuerySolution soln = results.next();
RDFNode node = soln.get("rank");
if (node != null && node.isLiteral()) {
// node.asLiteral().getInt() won't return an xsd:string that
// can be parsed as an int.
int rank = Integer.parseInt(node.asLiteral().getLexicalForm());
if (rank > maxRank) {
log.debug("setting maxRank to " + rank);
maxRank = rank;
}
}
}
} catch (NumberFormatException e) {
log.error("Invalid rank returned from query: not an integer value.");
} catch (Exception e) {
log.error(e, e);
}
log.debug("maxRank is: " + maxRank);
return maxRank;
}
private void sortAuthorshipIndividuals(List<Individual> authorships) {
DataPropertyComparator comp = new DataPropertyComparator(authorRankPredicate);
Collections.sort(authorships, comp);
private List<AuthorshipInfo> getAuthorshipInfo(
List<Map<String, String>> authorships) {
List<AuthorshipInfo> info = new ArrayList<AuthorshipInfo>();
String authorshipUri = "";
String authorshipName = "";
String authorUri = "";
String authorName = "";
for ( Map<String, String> authorship : authorships ) {
for (Entry<String, String> entry : authorship.entrySet() ) {
if ( entry.getKey().equals("authorshipURI") ) {
authorshipUri = entry.getValue();
}
else if ( entry.getKey().equals("authorshipName") ) {
authorshipName = entry.getValue();
}
else if ( entry.getKey().equals("authorURI") ) {
authorUri = entry.getValue();
}
else if ( entry.getKey().equals("authorName") ) {
authorName = entry.getValue();
}
}
AuthorshipInfo aaInfo = new AuthorshipInfo(authorshipUri, authorshipName, authorUri, authorName);
info.add(aaInfo);
}
log.debug("info = " + info);
return info;
}
//This is the information about authors the form will require
@ -467,8 +490,12 @@ public class AddAuthorsToInformationResourceGenerator extends VivoBaseGenerator
static final String DEFAULT_NS_TOKEN=null; //null forces the default NS
// protected String getAuthorshipsQuery() {
// return AUTHORSHIPS_QUERY;
// }
protected String getMaxRankQueryStr() {
return MAX_RANK_QUERY;
}
protected String getAuthorshipsQuery() {
return AUTHORSHIPS_QUERY;
}
}

View file

@ -308,15 +308,24 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
private String getN3ForNewBookNewEditor() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?newBook vivo:editor ?newEditor . \n " +
"?newEditor vivo:editorOf ?newBook . \n" +
"?newBook vivo:relatedBy ?editorship . \n" +
"?editorship vivo:relates ?newBook . \n" +
"?newBook <" + label + "> ?book . \n " +
"?editorship a vivo:Editorship . \n" +
"?editorship vivo:relates ?newEditor . \n" +
"?newEditor a <" + editorClass + "> . \n" +
"?newEditor vivo:relatedBy ?editorship . \n" +
"?newEditor <" + label + "> ?editor .";
}
private String getN3ForNewBookEditor() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?newBook vivo:editor ?editorUri . \n" +
"?editorUri vivo:editorOf ?newBook . " ;
"?newBook vivo:relatedBy ?editorship . \n" +
"?editorship vivo:relates ?newBook . \n" +
"?newBook <" + label + "> ?book . \n " +
"?editorship a vivo:Editorship . \n" +
"?editorship vivo:relates ?editorUri . \n" +
"?editorUri vivo:relatedBy ?editorship . ";
}
private String getN3ForNewBookNewPublisher() {
@ -396,30 +405,44 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
private String getN3ForNewEditor() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?pubUri vivo:editor ?newEditor . \n" +
"?pubUri vivo:relatedBy ?editorship . \n" +
"?editorship vivo:relates ?pubUri . \n" +
"?editorship a vivo:Editorship . \n" +
"?editorship vivo:relates ?newEditor . \n" +
"?newEditor a <" + editorClass + "> . \n" +
"?newEditor vivo:editorOf ?pubUri . \n" +
"?newEditor vivo:relatedBy ?editorship . \n" +
"?newEditor <" + label + "> ?editor .";
}
private String getN3ForEditor() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?pubUri vivo:editor ?editorUri . \n" +
"?editorUri vivo:editorOf ?pubUri . ";
"?pubUri vivo:relatedBy ?editorship . \n" +
"?editorship vivo:relates ?pubUri . \n" +
"?editorship a vivo:Editorship . \n" +
"?editorship vivo:relates ?editorUri . \n" +
"?editorUri vivo:relatedBy ?editorship . ";
}
private String getN3ForNewEditorNewPub() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?newPublication vivo:editor ?newEditor . \n" +
"?newPublication vivo:relatedBy ?editorship . \n" +
"?editorship vivo:relates ?newPublication . \n" +
"?newPublication <" + label + "> ?title ." +
"?editorship a vivo:Editorship . \n" +
"?editorship vivo:relates ?newEditor . \n" +
"?newEditor a <" + editorClass + "> . \n" +
"?newEditor vivo:editorOf ?newPublication . \n" +
"?newEditor vivo:relatedBy ?editorship . \n" +
"?newEditor <" + label + "> ?editor .";
}
private String getN3ForEditorNewPub() {
return "@prefix vivo: <" + vivoCore + "> . \n" +
"?newPublication vivo:editor ?editorUri . \n" +
"?editorUri vivo:editorOf ?newPublication . ";
"?newPublication vivo:relatedBy ?editorship . \n" +
"?editorship vivo:relates ?newPublication . \n" +
"?newPublication <" + label + "> ?title ." +
"?editorship vivo:relates ?editorUri . \n" +
"?editorship a vivo:Editorship . \n" +
"?editorUri vivo:relatedBy ?editorship . ";
}
private String getN3ForNewPublisher() {
@ -525,6 +548,7 @@ public class AddPublicationToPersonGenerator extends VivoBaseGenerator implement
newResources.put("newConference", DEFAULT_NS_TOKEN);
newResources.put("newEvent", DEFAULT_NS_TOKEN);
newResources.put("newEditor", DEFAULT_NS_TOKEN);
newResources.put("editorship", DEFAULT_NS_TOKEN);
newResources.put("vcardEditor", DEFAULT_NS_TOKEN);
newResources.put("vcardName", DEFAULT_NS_TOKEN);
newResources.put("newPublisher", DEFAULT_NS_TOKEN);

View file

@ -24,8 +24,8 @@ public class ModelUtils {
private static final String processPropertyInverseURI = "http://purl.obolibrary.org/obo/BFO_0000055";
private static final String nonProcessPropertyURI = "http://vivoweb.org/ontology/core#roleContributesTo";
private static final String nonProcessPropertyInverseURI = "http://vivoweb.org/ontology/core#contributingRole";
private static final String grantPropertyURI = "http://vivoweb.org/ontology/core#relates";
private static final String grantPropertyInverseURI = "http://vivoweb.org/ontology/core#relatedBy";
private static final String grantPropertyURI = "http://vivoweb.org/ontology/core#relatedBy";
private static final String grantPropertyInverseURI = "http://vivoweb.org/ontology/core#relates";
private static Set<String> processClass = new HashSet<String>();
static {