updates for multiple language labels and concept semantic types
This commit is contained in:
parent
b8e114c4e8
commit
fc9ac52786
11 changed files with 72 additions and 152 deletions
|
@ -7,6 +7,8 @@ import java.lang.Integer;
|
|||
import java.lang.String;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -31,6 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.dataGetter.ExecuteDataRetrieval;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||
|
@ -108,6 +111,8 @@ class IndividualResponseBuilder {
|
|||
*/
|
||||
// body.put("individual", wrap(itm, BeansWrapper.EXPOSE_SAFE));
|
||||
body.put("labelCount", getLabelCount(itm.getUri(), vreq));
|
||||
//We also need to know the number of available locales
|
||||
body.put("localesCount", SelectedLocale.getSelectableLocales(vreq).size());
|
||||
body.put("profileType", getProfileType(itm.getUri(), vreq));
|
||||
body.put("individual", wrap(itm, new ReadOnlyBeansWrapper()));
|
||||
|
||||
|
|
|
@ -258,6 +258,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
|||
HashMap<String, String> localeCodeToNameMap = this.getFullCodeToLanguageNameMap(locales);
|
||||
//the labels already added by the user
|
||||
ArrayList<Literal> existingLabels = this.getExistingLabels(config.getSubjectUri(), vreq);
|
||||
int numberExistingLabels = existingLabels.size();
|
||||
//existing labels keyed by language name and each of the list of labels is sorted by language name
|
||||
HashMap<String, List<LabelInformation>> existingLabelsByLanguageName = this.getLabelsSortedByLanguageName(existingLabels, localeCodeToNameMap, config, vreq);
|
||||
//Get available locales for the drop down for adding a new label, also sorted by language name
|
||||
|
@ -270,6 +271,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
|||
//Save labels sorted by language name, untyped have "untyped" as the language name value
|
||||
config.addFormSpecificData("labelsSortedByLanguageName", existingLabelsByLanguageName);
|
||||
config.addFormSpecificData("selectLocale",availableLocalesForAdd);
|
||||
config.addFormSpecificData("displayRemoveLink", (numberExistingLabels > 1));
|
||||
|
||||
|
||||
//How do we edit? Will need to see
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.query.Dataset;
|
||||
import com.hp.hpl.jena.query.Query;
|
||||
import com.hp.hpl.jena.query.QueryExecution;
|
||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
||||
import com.hp.hpl.jena.query.QueryFactory;
|
||||
import com.hp.hpl.jena.query.QuerySolutionMap;
|
||||
import com.hp.hpl.jena.query.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Property;
|
||||
import com.hp.hpl.jena.rdf.model.ResIterator;
|
||||
import com.hp.hpl.jena.rdf.model.Resource;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
import com.hp.hpl.jena.vocabulary.RDF;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapperFactory;
|
||||
|
||||
//We are representing semantic types from the UMLS Semantic Network as OWL Classes
|
||||
//and this preprocessor will add the appropriate class information to the TBox
|
||||
|
||||
public class ConceptSemanticTypesPreprocessor implements ModelChangePreprocessor {
|
||||
|
||||
private static String VIVOCore = "http://vivoweb.org/ontology/core#";
|
||||
private static String SKOSConceptType = "http://www.w3.org/2004/02/skos/core#Concept";
|
||||
private Log log = LogFactory.getLog(ConceptSemanticTypesPreprocessor.class);
|
||||
|
||||
private OntModel toUpdateModel = null;
|
||||
|
||||
//Custom constructor
|
||||
public ConceptSemanticTypesPreprocessor(OntModel updateModel) {
|
||||
this.toUpdateModel = updateModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocess(Model retractionsModel, Model additionsModel,
|
||||
HttpServletRequest request) {
|
||||
//Run a construct query against the additions model
|
||||
String prefixes = "PREFIX rdfs:<" + RDFS.getURI() + "> " +
|
||||
"PREFIX owl:<http://www.w3.org/2002/07/owl#> " +
|
||||
"PREFIX rdf:<" + RDF.getURI() + ">" +
|
||||
"PREFIX skos:<http://www.w3.org/2004/02/skos/core#>";
|
||||
String constructQuery = prefixes + " CONSTRUCT { " +
|
||||
"?semanticType rdf:type owl:Class. " +
|
||||
"?semanticType rdfs:subClassOf skos:Concept . " +
|
||||
"?semanticType rdfs:label ?label. " +
|
||||
"} WHERE { " +
|
||||
"?concept rdf:type ?semanticType. " +
|
||||
"?semanticType rdfs:label ?label . " +
|
||||
"?semanticType rdfs:subClassOf skos:Concept . " +
|
||||
"}";
|
||||
|
||||
//Execute construct query
|
||||
Model constructedModel = ModelFactory.createDefaultModel();
|
||||
|
||||
|
||||
log.debug("CONSTRUCT query string " + constructQuery);
|
||||
|
||||
Query query = null;
|
||||
try {
|
||||
query = QueryFactory.create(constructQuery, Syntax.syntaxARQ);
|
||||
} catch(Throwable th){
|
||||
log.error("Could not create CONSTRUCT SPARQL query for query " +
|
||||
"string. " + th.getMessage());
|
||||
log.error(constructQuery);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
additionsModel.getLock().enterCriticalSection(Lock.READ);
|
||||
QueryExecution qe = null;
|
||||
try {
|
||||
qe = QueryExecutionFactory.create(
|
||||
query, additionsModel);
|
||||
qe.execConstruct(constructedModel);
|
||||
} catch (Exception e) {
|
||||
log.error("Error getting constructed model for query string " + constructQuery);
|
||||
} finally {
|
||||
if (qe != null) {
|
||||
qe.close();
|
||||
}
|
||||
additionsModel.getLock().leaveCriticalSection();
|
||||
}
|
||||
|
||||
//Add constructed model to the designated update model
|
||||
toUpdateModel.enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
toUpdateModel.add(constructedModel);
|
||||
} catch (Exception e) {
|
||||
log.error("Error adding statements to update model for " + constructQuery);
|
||||
} finally {
|
||||
toUpdateModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
//Take this constructed model and remove from the additions model
|
||||
additionsModel.enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
additionsModel.remove(constructedModel.listStatements().toList());
|
||||
} catch (Exception e) {
|
||||
log.error("Error removing statements from additions model for " + constructQuery);
|
||||
} finally {
|
||||
additionsModel.leaveCriticalSection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue