Updates to generators

This commit is contained in:
hjkhjk54 2011-11-04 22:02:19 +00:00
parent 24aeb7bf34
commit 5c947b954f
7 changed files with 108 additions and 80 deletions

View file

@ -15,7 +15,9 @@
next statement -->
<#macro showRole statement property>
<#local linkedIndividual>
<a href="${profileUrl(statement.activity)}">${statement.activityLabel!statement.activityName}</a>
<#if statement?has_content && statement.activity?has_content>
<a href="${profileUrl(statement.activity)}">${statement.activityLabel!statement.activityName}</a>
</#if>
</#local>
<#local dateTime>

View file

@ -39,6 +39,8 @@
<#--Get selected activity type value if it exists, this is alternative to below-->
Test grant label: ${lvf.getFormFieldValue(editSubmission, editConfiguration, "grantLabel")} End Test
<#assign grantLabel = ""/>
<#if literalValues?keys?seq_contains("grantLabel") && (literalValues.grantLabel?size > 0)>
<#assign grantLabel = literalValues.grantLabel[0] />

View file

@ -22,3 +22,74 @@
</div>
</div>
</#macro>
<#--Given an edit configuration template object, get the current value for a uri field using the field name-->
<#function getEditConfigLiteralValue config varName>
<#local literalValues = config.existingLiteralValues >
<#if (literalValues?keys?seq_contains(varName)) && (literalValues[varName]?size > 0)>
<#return literalValues[varName][0] >
</#if>
<#return "">
</#function>
<#--Given an edit configuration template object, get the current value for a literal field using the field name-->
<#function getEditConfigUriValue config varName>
<#local uriValues = config.existingUriValues />
<#if (uriValues?keys?seq_contains(varName)) && (uriValues[varName]?size > 0)>
<#return uriValues[varName][0] >
</#if>
<#return "">
</#function>
<#--Now check whether a given value returns either a uri or a literal value, if one empty then use other and
return - returns empty string if no value found-->
<#function getEditConfigValue config varName>
<#local returnValue = getEditConfigUriValue(config, varName) />
<#if (returnValue?length = 0)>
<#local returnValue = getEditConfigLiteralValue(config, varName) />
</#if>
<#return returnValue>
</#function>
<#--Given edit submission object find values->
<#function getEditSubmissionLiteralValue submission varName>
<#local literalValues = submission.literalsFromForm >
<#if (literalValues?keys?seq_contains(varName)) && (literalValues[varName]?size > 0)>
<#return literalValues[varName][0] >
</#if>
<#return "">
</#function>
<#--Given an edit configuration template object, get the current value for a literal field using the field name-->
<#function getEditSubmissionUriValue submission varName>
<#local uriValues = submission.urisFromForm />
<#if (uriValues?keys?seq_contains(varName)) && (uriValues[varName]?size > 0)>
<#return uriValues[varName][0] >
</#if>
<#return "">
</#function>
<#--Get edit submission value for either literal or uri-->
<#function getEditSubmissionValue submission varName>
<#local returnValue = getEditSubmissionUriValue(submission, varName) />
<#if (returnValue?length = 0)>
<#local returnValue = getEditSubmissionLiteralValue(submission, varName) />
</#if>
<#return returnValue>
</#function>
<#--Get the value for the form field, checking edit submission first and then edit configuration-->
<#function getFormFieldValue submission config varName>
<#local returnValue = "">
<#if submission?has_content && submission.submissionExists = true>
<#local returnValue = getEditSubmissionValue(submission varName)>
<#else>
<#local returnValue = getEditConfigValue(config varName)>
</#if>
<#return returnValue>
</#function>

View file

@ -85,17 +85,6 @@ public class AddEditorRoleToPersonGenerator extends AddRoleToPersonTwoStageGener
editConfiguration.setTemplate(template);
}
//The default activityToRolePredicate and roleToActivityPredicates are
//correct for this subclass so they don't need to be overwritten
public String getActivityToRolePredicate(VitroRequest vreq) {
return "http://vivoweb.org/ontology/core#linkedRole";
}
public String getRoleToActivityPredicate(VitroRequest vreq) {
return "http://vivoweb.org/ontology/core#forInformationResource";
}
//role type will always be set based on particular form
public String getRoleType(VitroRequest vreq) {
//TODO: Get dynamic way of including vivoweb ontology

View file

@ -540,11 +540,7 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
//Replacement should only happen when we have an actual predicate
String replaceRoleToActivityPredicate = getRoleToActivityPredicate(vreq);
//if no filters to add, this means an actual parameter exists for the role to activity predicate and that should be utilized
//as the replacement
if(!doAddFilterToRoleToActivityQuery(vreq)) {
activityTypeQuery = QueryUtils.subUriForQueryVar(activityTypeQuery, "predicate", replaceRoleToActivityPredicate);
}
activityTypeQuery = QueryUtils.subUriForQueryVar(activityTypeQuery, "predicate", replaceRoleToActivityPredicate);
log.debug("Activity type query: " + activityTypeQuery);
return activityTypeQuery;
@ -557,9 +553,7 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
"SELECT ?existingActivityType WHERE { \n" +
" ?role ?predicate ?existingActivity . \n" +
" ?existingActivity vitro:mostSpecificType ?existingActivityType . \n";
if(doAddFilterToRoleToActivityQuery(vreq)) {
query += getFilterRoleToActivityPredicate("predicate");
}
query += getFilterRoleToActivityPredicate("predicate");
query+= "}";
return query;
}
@ -572,9 +566,7 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
" ?role ?predicate ?existingActivity . \n" +
" ?existingActivity vitro:mostSpecificType ?existingActivityType . \n" +
" ?existingActivityType rdfs:subClassOf ?objectClassUri . \n";
if(doAddFilterToRoleToActivityQuery(vreq)) {
query += getFilterRoleToActivityPredicate("predicate");
}
query += getFilterRoleToActivityPredicate("predicate");
query+= "}";
return query;
}
@ -586,9 +578,7 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
" ?role ?predicate ?existingActivity . \n" +
" ?existingActivity vitro:mostSpecificType ?existingActivityType . \n" +
" ?existingActivityType vitro:inClassGroup ?classgroup . \n";
if(doAddFilterToRoleToActivityQuery(vreq)) {
query += getFilterRoleToActivityPredicate("predicate");
}
query += getFilterRoleToActivityPredicate("predicate");
query+= "}";
return query;
}
@ -601,18 +591,12 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
String roleToActivityPredicate = getRoleToActivityPredicate(vreq);
//Portion below for multiple possible predicates
if(doAddFilterToRoleToActivityQuery(vreq)) {
List<String> predicates = getPossibleRoleToActivityPredicates();
List<String> addToQuery = new ArrayList<String>();
query += "SELECT ?existingActivity WHERE { \n" +
" ?role ?predicate ?existingActivity . \n ";
query += getFilterRoleToActivityPredicate("predicate");
query += "}";
} else {
query += "SELECT ?existingActivity WHERE { ?role <" +roleToActivityPredicate + "> ?existingActivity . }";
}
List<String> predicates = getPossibleRoleToActivityPredicates();
List<String> addToQuery = new ArrayList<String>();
query += "SELECT ?existingActivity WHERE { \n" +
" ?role ?predicate ?existingActivity . \n ";
query += getFilterRoleToActivityPredicate("predicate");
query += "}";
return query;
}
@ -658,20 +642,11 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
"PREFIX rdfs: <" + RDFS.getURI() + "> \n";
String roleToActivityPredicate = getRoleToActivityPredicate(vreq);
if(doAddFilterToRoleToActivityQuery(vreq)) {
query += "SELECT ?existingTitle WHERE { \n" +
"?role ?predicate ?existingActivity . \n" +
"?existingActivity rdfs:label ?existingTitle . \n";
query += getFilterRoleToActivityPredicate("predicate");
query += "}";
} else {
query += "SELECT ?existingTitle WHERE { \n" +
"?role <" + roleToActivityPredicate + "> ?existingActivity . \n" +
"?existingActivity rdfs:label ?existingTitle . }";
}
query += "SELECT ?existingTitle WHERE { \n" +
"?role ?predicate ?existingActivity . \n" +
"?existingActivity rdfs:label ?existingTitle . \n";
query += getFilterRoleToActivityPredicate("predicate");
query += "}";
return query;
}
@ -1055,7 +1030,6 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
public String getActivityToRolePredicate(VitroRequest vreq) {
return getActivityToRolePlaceholder();
//return getDefaultActivityToRolePredicate();
}
//This has a default value, but note that even that will not be used
@ -1065,21 +1039,10 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
//placeholder value by default
public String getRoleToActivityPredicate(VitroRequest vreq) {
return getRoleToActivityPlaceholder();
//return getDefaultRoleToActivityPredicate();
}
//Ensure when overwritten that this includes the <> b/c otherwise the query won't work
//Some values will have a default value
//activityToRolePredicate
public String getDefaultActivityToRolePredicate() {
return "http://vivoweb.org/ontology/core#relatedRole";
}
//roleToActivityPredicate
public String getDefaultRoleToActivityPredicate() {
return "http://vivoweb.org/ontology/core#roleIn";
}
public List<String> getPossibleRoleToActivityPredicates() {
return ModelUtils.getPossiblePropertiesForRole();
@ -1173,15 +1136,6 @@ public abstract class AddRoleToPersonTwoStageGenerator implements EditConfigurat
editConfiguration.setFormSpecificData(formSpecificData);
}
//Do add filter fo rroel to activity or activity to role predicates
public boolean doAddFilterToRoleToActivityQuery(VitroRequest vreq) {
return (getRoleToActivityPredicate(vreq) == getRoleToActivityPlaceholder());
}
public boolean doAddFilterToActivityToRoleQuery(VitroRequest vreq) {
return (getActivityToRolePredicate(vreq) == getActivityToRolePlaceholder());
}
public String getFilterRoleToActivityPredicate(String predicateVar) {
String addFilter = "FILTER (";

View file

@ -66,13 +66,13 @@ public abstract class RoleToPredicatePreprocessor extends BaseEditSubmissionPrep
Map<String, List<String>> urisFromForm = submission.getUrisFromForm();
if(type != null) {
ObjectProperty roleToItemProperty = getCorrectProperty(type, wadf);
String roleToItemPredicate = roleToItemProperty.getURI();
String itemToRolePredicate = roleToItemProperty.getURIInverse();
String roleToItemPredicateURI = roleToItemProperty.getURI();
String itemToRolePredicateURI = roleToItemProperty.getURIInverse();
List<String> predicates = new ArrayList<String>();
predicates.add(roleToItemPredicate);
predicates.add(roleToItemPredicateURI);
List<String> inversePredicates = new ArrayList<String>();
inversePredicates.add(itemToRolePredicate);
inversePredicates.add(itemToRolePredicateURI);
//Populate the two fields in edit submission
if(urisFromForm.containsKey(roleToItemPredicate)) {
urisFromForm.remove(roleToItemPredicate);

View file

@ -11,6 +11,7 @@ import javax.servlet.ServletOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@ -58,7 +59,16 @@ public class UMLSConceptSearch extends AbstractConceptSearch{
}
if(json.has("BestMatch")) {
JSONArray bestMatchArray = json.getJSONArray("BestMatch");
int len = bestMatchArray.length();
int i;
for(i = 0; i < len; i++) {
JSONObject o = bestMatchArray.getJSONObject(i);
String definition = o.getString("definition");
String label = o.getString("label");
String CUI = o.getString("CUI");
String type = o.getString("type");
}
}
} catch(Exception ex) {
log.error("Error making json object out of output");