diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaCsv2RdfController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaCsv2RdfController.java
index 1f51d023a..ea83c0cf5 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaCsv2RdfController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaCsv2RdfController.java
@@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.controller.jena;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -34,7 +35,6 @@ import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
public class JenaCsv2RdfController extends BaseEditController{
private static final String CSV2RDF_JSP = "/jenaIngest/csv2rdf.jsp";
- private static final String INGEST_MENU_JSP = "/jenaIngest/ingestMenu.jsp";
private static final String CSV2RDF_SELECT_URI_JSP = "/jenaIngest/csv2rdfSelectUri.jsp";
private static int maxFileSizeInBytes = 1024 * 1024 * 2000; //2000mb
@@ -62,17 +62,20 @@ public class JenaCsv2RdfController extends BaseEditController{
if ("csv2rdf".equals(actionStr)) {
String csvUrl = request.getParameter("csvUrl");
if (!csvUrl.isEmpty() || !filePath.isEmpty()) {
- String[] sourceModel = new String[1];
- sourceModel[0] = doExecuteCsv2Rdf(request,fileStream,filePath);
- Model model = ModelFactory.createDefaultModel();
+ String destinationModelNameStr = request.getParameter(
+ "destinationModelName");
+ Model csv2rdfResult = doExecuteCsv2Rdf(
+ request, fileStream, filePath);
ModelMaker maker = getVitroJenaModelMaker(request);
Boolean csv2rdf = true;
JenaIngestUtils utils = new JenaIngestUtils();
- Map> propertyMap = utils.generatePropertyMap(sourceModel, model, maker);
+ List resultList = new ArrayList();
+ resultList.add(csv2rdfResult);
+ Map> propertyMap =
+ utils.generatePropertyMap(resultList, maker);
request.setAttribute("propertyMap",propertyMap);
- getServletContext().setAttribute("sourceModel", sourceModel);
- getServletContext().setAttribute("csv2rdf",csv2rdf);
- request.setAttribute("destinationModelName", sourceModel[0]);
+ request.setAttribute("csv2rdf", csv2rdf);
+ request.setAttribute("destinationModelName", destinationModelNameStr);
request.setAttribute("title","URI Select");
request.setAttribute("bodyJsp", CSV2RDF_SELECT_URI_JSP);
} else {
@@ -88,9 +91,7 @@ public class JenaCsv2RdfController extends BaseEditController{
try {
rd.forward(request, response);
} catch (Exception e) {
- System.out.println(this.getClass().getName()+" could not forward to view.");
- System.out.println(e.getMessage());
- System.out.println(e.getStackTrace());
+ throw new RuntimeException(e);
}
}
@@ -106,7 +107,7 @@ public class JenaCsv2RdfController extends BaseEditController{
return;
}
- public String doExecuteCsv2Rdf(VitroRequest vreq,FileItem fileStream, String filePath) {
+ public Model doExecuteCsv2Rdf(VitroRequest vreq, FileItem fileStream, String filePath) {
char[] quoteChars = {'"'};
String namespace = "";
String tboxNamespace = vreq.getParameter("tboxNamespace");
@@ -139,25 +140,26 @@ public class JenaCsv2RdfController extends BaseEditController{
is = fileStream.getInputStream();
} catch (IOException e) {
- System.out.println("IOException opening URL "+csvUrl);
- return null;
+ throw new RuntimeException("Unable to access URL " + csvUrl);
}
Model[] models = null;
try {
- models = c2r.convertToRdf(is,vreq,destination);
+ models = c2r.convertToRdf(
+ is, vreq.getWebappDaoFactory(), destination);
} catch (IOException e) {
- System.out.println("IOException converting "+csvUrl+" to RDF");
+ throw new RuntimeException(
+ "Unable to convert " + csvUrl + " to RDF");
}
- if (destination != null) {
- destination.add(models[0]);
- }
+ // TODO: rework this
+ vreq.getSession().setAttribute("csv2rdfResult", models[0]);
if (tboxDestination != null) {
tboxDestination.add(models[1]);
}
- return destinationModelNameStr;
+
+ return models[0];
}
private Model getModel(String name, HttpServletRequest request) {
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java
index 411cd9635..f51a79c2c 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java
@@ -11,6 +11,7 @@ import java.lang.reflect.Method;
import java.sql.SQLException;
import java.text.Collator;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -68,7 +69,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
-import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
@@ -145,8 +145,6 @@ public class JenaIngestController extends BaseEditController {
return; // don't attempt to display a JSP
} else if("clearModel".equals(actionStr)) {
processClearModelRequest(vreq, maker, modelType);
- } else if("setWriteLayer".equals(actionStr)) {
- processSetWriteLayerRequest(vreq, maker, modelType);
} else if("attachModel".equals(actionStr)) {
processAttachModelRequest(vreq, maker, modelType);
} else if("detachModel".equals(actionStr)) {
@@ -337,13 +335,13 @@ public class JenaIngestController extends BaseEditController {
} catch (com.hp.hpl.jena.shared.CannotEncodeCharacterException cece) {
// there's got to be a better way to do this
byte[] badCharBytes = String.valueOf(cece.getBadChar()).getBytes();
- System.out.println("Cannot encode character with byte values: (decimal) ");
+ String errorMsg = "Cannot encode character with byte values: (decimal) ";
for (int i=0; i> propertyMap = utils.generatePropertyMap(sourceModel, model, maker);
- getServletContext().setAttribute("sourceModel",sourceModel);
+ if(sourceModel != null && sourceModel.length != 0) {
+ List sourceModelList = new ArrayList();
+ for (int i = 0; i < sourceModel.length ; i++) {
+ Model m = maker.getModel(sourceModel[i]);
+ if (m != null) {
+ sourceModelList.add(m);
+ }
+ }
+ Map> propertyMap =
+ utils.generatePropertyMap(sourceModelList, maker);
+ List sourceModelNameList = Arrays.asList(sourceModel);
+ vreq.setAttribute("sourceModel",sourceModelNameList);
vreq.setAttribute("propertyMap", propertyMap);
+ vreq.setAttribute("enablePropertyPatternURIs", !propertyMap.isEmpty());
vreq.setAttribute("title","URI Select");
vreq.setAttribute("bodyJsp",RENAME_BNODES_URI_SELECT_JSP);
} else {
@@ -421,12 +404,21 @@ public class JenaIngestController extends BaseEditController {
String namespaceEtcStr = vreq.getParameter("namespaceEtcStr");
String pattern = vreq.getParameter("pattern");
String concatenate = vreq.getParameter("concatenate");
- String[] sourceModel = (String[])getServletContext().getAttribute("sourceModel");
- if(namespaceEtcStr!=null && !namespaceEtcStr.isEmpty()){
- if(concatenate.equals("integer")){
- doRenameBNodes(vreq,namespaceEtcStr, false, null, sourceModel);
+ String[] sourceModel = (String[]) vreq.getParameterValues("sourceModelName");
+ if(namespaceEtcStr != null) {
+ if (namespaceEtcStr.isEmpty()) {
+ if ("true".equals(vreq.getParameter("csv2rdf"))) {
+ processCsv2rdfRequest(vreq, maker, modelType);
+ return;
+ } else {
+ vreq.setAttribute("errorMsg", "Please enter a value.");
+ processRenameBNodesRequest(vreq, maker, modelType);
+ return;
+ }
}
- else{
+ if (concatenate.equals("integer")) {
+ doRenameBNodes(vreq,namespaceEtcStr, false, null, sourceModel);
+ } else {
pattern = pattern.trim();
doRenameBNodes(vreq,namespaceEtcStr, true, pattern, sourceModel);
}
@@ -695,7 +687,7 @@ public class JenaIngestController extends BaseEditController {
* calling method that does the merge operation.
*/
String result = utils.doMerge(uri1,uri2,baseOntModel,ontModel,infOntModel,usePrimaryLabelOnly);
- getServletContext().setAttribute("leftoverModel", utils.getLeftOverModel());
+ vreq.getSession().setAttribute("leftoverModel", utils.getLeftOverModel());
vreq.setAttribute("result",result);
vreq.setAttribute("title","Merge Resources");
vreq.setAttribute("bodyJsp",MERGE_RESULT);
@@ -710,15 +702,32 @@ public class JenaIngestController extends BaseEditController {
HttpServletResponse response,
ModelMaker maker,
String modelType) {
- String uri1 = vreq.getParameter("uri1");
- String uri2 = vreq.getParameter("uri2");
- if(uri1!=null){
- String result = doRename(uri1,uri2,response);
- vreq.setAttribute("result",result);
- vreq.setAttribute("title","Rename Resources");
- vreq.setAttribute("bodyJsp",RENAME_RESULT);
- }
- else{
+ String oldNamespace = vreq.getParameter("oldNamespace");
+ String newNamespace = vreq.getParameter("newNamespace");
+ String errorMsg = "";
+ if (oldNamespace != null) {
+ if (oldNamespace.isEmpty() && !newNamespace.isEmpty()) {
+ errorMsg = "Please enter the old namespace to be changed.";
+ } else if (!oldNamespace.isEmpty() && newNamespace.isEmpty()) {
+ errorMsg = "Please enter the new namespace.";
+ } else if (oldNamespace.isEmpty() && newNamespace.isEmpty()) {
+ errorMsg = "Please enter the namespaces.";
+ } else if (oldNamespace.equals(newNamespace)) {
+ errorMsg = "Please enter two different namespaces.";
+ }
+ if (!errorMsg.isEmpty()) {
+ vreq.setAttribute("errorMsg", errorMsg);
+ vreq.setAttribute("oldNamespace", oldNamespace);
+ vreq.setAttribute("newNamespace", newNamespace);
+ vreq.setAttribute("title","Rename Resource");
+ vreq.setAttribute("bodyJsp",RENAME_RESOURCE);
+ } else {
+ String result = doRename(oldNamespace, newNamespace, response);
+ vreq.setAttribute("result",result);
+ vreq.setAttribute("title","Rename Resources");
+ vreq.setAttribute("bodyJsp",RENAME_RESULT);
+ }
+ } else{
vreq.setAttribute("title","Rename Resource");
vreq.setAttribute("bodyJsp",RENAME_RESOURCE);
}
@@ -728,8 +737,8 @@ public class JenaIngestController extends BaseEditController {
HttpServletResponse response,
ModelMaker maker,
String modelType) {
- //Model lmodel = (Model)request.getSession().getAttribute("leftoverModel");
- Model lmodel = (Model)getServletContext().getAttribute("leftoverModel");
+
+ Model lmodel = (Model) vreq.getSession().getAttribute("leftoverModel");
response.setContentType("RDF/XML-ABBREV");
try {
OutputStream outStream = response.getOutputStream();
@@ -745,7 +754,7 @@ public class JenaIngestController extends BaseEditController {
private ModelMaker getVitroJenaModelMaker(HttpServletRequest request) {
ModelMaker myVjmm = (ModelMaker) request.getSession().getAttribute("vitroJenaModelMaker");
- myVjmm = (myVjmm == null) ? (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker") : myVjmm;
+ myVjmm = (myVjmm == null) ? (ModelMaker) getServletContext().getAttribute("vitroJenaSDBModelMaker") : myVjmm;
return new VitroJenaSpecialModelMaker(myVjmm, request);
}
@@ -783,7 +792,7 @@ public class JenaIngestController extends BaseEditController {
private void doRemoveModel(String modelName, ModelMaker modelMaker) {
//Try to detach first since it cause problems to remove an attached model.
doDetachModel(modelName, modelMaker);
- System.out.println("Removing "+modelName+" from webapp");
+ log.debug("Removing " + modelName + " from webapp");
modelMaker.removeModel(modelName);
}
@@ -861,13 +870,28 @@ public class JenaIngestController extends BaseEditController {
private void doRenameBNodes(VitroRequest vreq, String namespaceEtc, boolean patternBoolean, String pattern, String[] sourceModel) {
OntModel source = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
String property = vreq.getParameter("property");
- Boolean csv2rdf = (Boolean)getServletContext().getAttribute("csv2rdf");
- for (int i=0; i urisToChange = new LinkedList();
ontModel.enterCriticalSection(Lock.READ);
try {
@@ -1272,37 +1250,22 @@ public class JenaIngestController extends BaseEditController {
Matcher matcher = p.matcher(candidateString);
newURIStr = matcher.replaceFirst(newNamespace);
long time3 = System.currentTimeMillis();
- log.info("time to get new uri: " +
+ log.debug("time to get new uri: " +
Long.toString(time3 - time2));
- log.info("Renaming "+ oldURIStr + " to " + newURIStr);
+ log.debug("Renaming "+ oldURIStr + " to " + newURIStr);
ResourceUtils.renameResource(res,newURIStr);
ResourceUtils.renameResource(infRes,newURIStr);
long time4 = System.currentTimeMillis();
- log.info(" time to rename : " + Long.toString( time4 - time3));
- log.info(" time for one resource: " +
+ log.debug(" time to rename : " + Long.toString( time4 - time3));
+ log.debug(" time for one resource: " +
Long.toString( time4 -time1));
} finally {
infOntModel.leaveCriticalSection();
ontModel.leaveCriticalSection();
baseOntModel.leaveCriticalSection();
}
- try {
- Thread.currentThread().sleep(200);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
counter++;
}
- /*baseOntModel.enterCriticalSection(Lock.WRITE);
- ontModel.enterCriticalSection(Lock.WRITE);
- try{
- baseOntModel.getBaseModel().notifyEvent(new EditEvent(null,true));
- baseOntModel.getBaseModel().notifyEvent(new EditEvent(null,false));
- } finally {
- ontModel.leaveCriticalSection();
- baseOntModel.leaveCriticalSection();
- }*/
result = counter.toString() + " resources renamed";
return result;
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/Csv2Rdf.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/Csv2Rdf.java
index 66f17bd05..769e53b0c 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/Csv2Rdf.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/Csv2Rdf.java
@@ -60,7 +60,7 @@ public class Csv2Rdf {
return convertToRdf(fis, null, null);
}
- public Model[] convertToRdf(InputStream fis,VitroRequest vreq, Model destination) throws IOException {
+ public Model[] convertToRdf(InputStream fis, WebappDaoFactory wadf, Model destination) throws IOException {
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
OntModel tboxOntModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
ontModel.addSubModel(tboxOntModel);
@@ -70,8 +70,8 @@ public class Csv2Rdf {
cReader.setSeperator(separatorChar);
cReader.setQuoteCharacters(quoteChars);
- URIGenerator uriGen = (vreq != null && destination != null)
- ? new RandomURIGenerator(vreq, destination)
+ URIGenerator uriGen = (wadf != null && destination != null)
+ ? new RandomURIGenerator(wadf, destination)
: new SequentialURIGenerator();
List fileRows = cReader.parse(fis);
@@ -115,12 +115,12 @@ public class Csv2Rdf {
private class RandomURIGenerator implements URIGenerator {
- private VitroRequest vreq;
+ private WebappDaoFactory wadf;
private Model destination;
private Random random = new Random(System.currentTimeMillis());
- public RandomURIGenerator(VitroRequest vreq, Model destination) {
- this.vreq = vreq;
+ public RandomURIGenerator(WebappDaoFactory webappDaoFactory, Model destination) {
+ this.wadf = webappDaoFactory;
this.destination = destination;
}
@@ -132,7 +132,7 @@ public class Csv2Rdf {
if(namespace!=null && !namespace.isEmpty()){
while( uriIsGood == false && attempts < 30 ){
uri = namespace+individualNameBase+random.nextInt( Math.min(Integer.MAX_VALUE,(int)Math.pow(2,attempts + 13)) );
- String errMsg = vreq.getWebappDaoFactory().checkURI(uri);
+ String errMsg = wadf.checkURI(uri);
Resource res = ResourceFactory.createResource(uri);
inDestination = destination.contains(res, null);
if( errMsg != null && !inDestination)
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestUtils.java
index 48eeabca6..68f2af94d 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestUtils.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/JenaIngestUtils.java
@@ -173,7 +173,11 @@ public class JenaIngestUtils {
if (stmt != null) {
Resource outRes = stmt.getSubject();
if(stmt.getObject().isLiteral()){
- ResourceUtils.renameResource(outRes,namespaceEtc+pattern+"_"+stmt.getObject().toString());
+ String value = ((Literal) stmt.getObject()).getLexicalForm();
+ String suffix = (pattern.contains("$$$"))
+ ? pattern.replace("$$$", value)
+ : pattern + value;
+ ResourceUtils.renameResource(outRes, namespaceEtc + suffix);
}
doneSet.add(res.getId().toString());
}
@@ -191,70 +195,58 @@ public class JenaIngestUtils {
}
- public Map generatePropertyMap(String[] sourceModel, Model model, ModelMaker maker){
+ public Map> generatePropertyMap(List sourceModels, ModelMaker maker){
Map> propertyMap = Collections.synchronizedMap(new HashMap>());
Set doneList = new HashSet();
- if(sourceModel!=null && sourceModel.length!=0){
- for(String modelName : sourceModel){
- if(modelName != null){
- model = maker.getModel(modelName);
- ClosableIterator cItr = model.listSubjects();
- while(cItr.hasNext()){
- Resource res = (Resource) cItr.next();
- if(res.isAnon() && !doneList.contains(res.getId())){
-
- doneList.add(res.getId().toString());
- StmtIterator stmtItr = model.listStatements(res, (Property)null, (RDFNode)null);
- while(stmtItr.hasNext()){
- Statement stmt = stmtItr.next();
- if(!stmt.getObject().isResource()){
- if(propertyMap.containsKey(stmt.getPredicate().getURI())){
- LinkedList linkList = propertyMap.get(stmt.getPredicate().getURI());
- linkList.add(stmt.getObject().toString());
-
- }
- else{
- propertyMap.put(stmt.getPredicate().getURI(), new LinkedList());
- LinkedList linkList = propertyMap.get(stmt.getPredicate().getURI());
- linkList.add(stmt.getObject().toString());
-
- }
-
- }
-
+ for(Model model : sourceModels) {
+ ClosableIterator cItr = model.listSubjects();
+ while(cItr.hasNext()){
+ Resource res = (Resource) cItr.next();
+ if(res.isAnon() && !doneList.contains(res.getId())){
+ doneList.add(res.getId().toString());
+ StmtIterator stmtItr = model.listStatements(res, (Property)null, (RDFNode)null);
+ while(stmtItr.hasNext()){
+ Statement stmt = stmtItr.next();
+ if(!stmt.getObject().isResource()){
+ if(propertyMap.containsKey(stmt.getPredicate().getURI())){
+ LinkedList linkList = propertyMap.get(stmt.getPredicate().getURI());
+ linkList.add(stmt.getObject().toString());
}
- }
+ else{
+ propertyMap.put(stmt.getPredicate().getURI(), new LinkedList());
+ LinkedList linkList = propertyMap.get(stmt.getPredicate().getURI());
+ linkList.add(stmt.getObject().toString());
+ }
+ }
}
- cItr = model.listObjects();
- while(cItr.hasNext()){
- RDFNode rdfn = (RDFNode) cItr.next();
- if(rdfn.isResource()){
- Resource res = (Resource)rdfn;
- if(res.isAnon() && !doneList.contains(res.getId())){
- doneList.add(res.getId().toString());
- StmtIterator stmtItr = model.listStatements(res, (Property)null, (RDFNode)null);
- while(stmtItr.hasNext()){
- Statement stmt = stmtItr.next();
- if(!stmt.getObject().isResource()){
- if(propertyMap.containsKey(stmt.getPredicate().getURI())){
- LinkedList linkList = propertyMap.get(stmt.getPredicate().getURI());
- linkList.add(stmt.getObject().toString());
-
- }
- else{
- propertyMap.put(stmt.getPredicate().getURI(), new LinkedList());
- LinkedList linkList = propertyMap.get(stmt.getPredicate().getURI());
- linkList.add(stmt.getObject().toString());
-
- }
- }
- }
- }
- }
- }
- cItr.close();
}
}
+ cItr = model.listObjects();
+ while(cItr.hasNext()){
+ RDFNode rdfn = (RDFNode) cItr.next();
+ if(rdfn.isResource()){
+ Resource res = (Resource)rdfn;
+ if(res.isAnon() && !doneList.contains(res.getId())){
+ doneList.add(res.getId().toString());
+ StmtIterator stmtItr = model.listStatements(res, (Property)null, (RDFNode)null);
+ while(stmtItr.hasNext()){
+ Statement stmt = stmtItr.next();
+ if(!stmt.getObject().isResource()){
+ if(propertyMap.containsKey(stmt.getPredicate().getURI())){
+ LinkedList linkList = propertyMap.get(stmt.getPredicate().getURI());
+ linkList.add(stmt.getObject().toString());
+ }
+ else{
+ propertyMap.put(stmt.getPredicate().getURI(), new LinkedList());
+ LinkedList linkList = propertyMap.get(stmt.getPredicate().getURI());
+ linkList.add(stmt.getObject().toString());
+ }
+ }
+ }
+ }
+ }
+ }
+ cItr.close();
}
return propertyMap;
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/SesameSyncUtils.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/SesameSyncUtils.java
index 96ef68acc..9875e5238 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/SesameSyncUtils.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/utils/jena/SesameSyncUtils.java
@@ -6,6 +6,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -18,7 +20,16 @@ import org.openrdf.repository.http.HTTPRepository;
import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFParseException;
+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.QuerySolution;
+import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.vocabulary.OWL;
public class SesameSyncUtils {
@@ -42,11 +53,16 @@ public class SesameSyncUtils {
} else {
myConn.clear();
}
-
+
PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream(in);
+
+
+
try {
- new Thread(new JenaOutputter(jenaModel, out), "SesameSyncUtilities.JenaOutputter").start();
+
+ new Thread(new JenaOutputter(jenaModel, out, myConn), "SesameSyncUtilities.JenaOutputter").start();
+
if (contextRes != null) {
myConn.add(in,"http://example.org/base/", RDFFormat.NTRIPLES, contextRes);
} else {
@@ -69,19 +85,62 @@ public class SesameSyncUtils {
}
+ private List getIndividualURIs(Model model) {
+ List individualURIs = new ArrayList();
+ String queryStr = "SELECT DISTINCT ?s WHERE { \n" +
+ " ?s a <" + OWL.Thing.getURI() + "> \n" +
+ "}";
+ Query query = QueryFactory.create(queryStr);
+ QueryExecution qe = QueryExecutionFactory.create(query, model);
+ try {
+ ResultSet rs = qe.execSelect();
+ while (rs.hasNext()) {
+ QuerySolution qsoln = rs.nextSolution();
+ String individualURI = qsoln.getResource("s").getURI();
+ if (individualURI != null) {
+ individualURIs.add(individualURI);
+ }
+ }
+ } finally {
+ qe.close();
+ }
+ return individualURIs;
+ }
+
private class JenaOutputter implements Runnable {
private Model model;
private OutputStream out;
+ private RepositoryConnection rconn;
- public JenaOutputter(Model model, OutputStream out) {
+ public JenaOutputter(Model model, OutputStream out, RepositoryConnection rconn) {
this.model = model;
this.out = out;
+ this.rconn = rconn;
}
public void run() {
+ Model t = ModelFactory.createDefaultModel();
try {
- model.write(out, "N-TRIPLE");
+ List individualURIs = getIndividualURIs(model);
+ log.info(individualURIs.size() + " individuals to send to Sesame");
+ int i = 0;
+ for (String individualURI : individualURIs) {
+ t.removeAll();
+ t.add(model.listStatements(
+ model.getResource(
+ individualURI), null, (RDFNode) null));
+ t.write(out, "N-TRIPLE");
+ i++;
+ if (i % 100 == 0) {
+ try {
+ rconn.commit();
+ } catch (Throwable e) {
+ log.error(e, e);
+ }
+ log.info(i + " individuals sent to Sesame");
+ }
+ }
} finally {
try {
out.flush();
diff --git a/webapp/web/jenaIngest/csv2rdf.jsp b/webapp/web/jenaIngest/csv2rdf.jsp
index 41f7f0657..11d24440d 100644
--- a/webapp/web/jenaIngest/csv2rdf.jsp
+++ b/webapp/web/jenaIngest/csv2rdf.jsp
@@ -17,7 +17,7 @@
ModelMaker maker = (ModelMaker) request.getSession().getAttribute("vitroJenaModelMaker");
if (maker == null) {
- maker = (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker");
+ maker = (ModelMaker) getServletContext().getAttribute("vitroJenaSDBModelMaker");
}
%>
@@ -36,15 +36,27 @@
Or upload a file from your computer:
+
+
This tool will automatically generate a mini ontology to represent the
+ data in the CSV file. A property will be produced for each column in the
+ spreadsheet, based on the text in the header for that column.
In what
+ namespace should these properties be created?
-
Namespace in which to generate class and properties
+
Namespace in which to generate properties
+
+
Each row in the spreadsheet will produce an resource. Each of these
+ resources will be a member of a class in the namespace selected above.
+
What should the local name of this class be? This is normally a word or two
+ in "camel case" starting with an uppercase letter. (For example, if the
+ spreadsheet represents a list of faculty members, you might enter
+ "FacultyMember" on the next line.)
-
Class Name for Resources
+
Class Local Name for Resources
-
Destination Model
+
Model in which to save the converted spreadsheet data
-
Destination Model for TBox
+
Model in which to save the automatically-generated ontology
+
+
+
The data in the CSV file will initially be represented using blank
+ nodes (RDF resources without URIs). You will choose how to assign
+ URIs to these resources in the next step.
URIs will be constructed from the following string:
+
URIs will be constructed using the following base string:
-
You can concatenate above string with random integer OR your own pattern based on values of one of the properties (Properties will be enabled in the dropdown)
+
Each resource will be assigned a URI by taking the above string and
+ adding either a random integer, or a string based on the value of one of the
+ the properties of the resource
- No, concatenate with random integer
+ Use random integer
- Yes, concatenate with my pattern
+ Use pattern based on values of
<% Map> propertyMap = (Map) request.getAttribute("propertyMap");
@@ -75,12 +79,16 @@ function disableProperties(){
%>
-
Enter your pattern that will prefix property value with an underscore eg. depID_$$$ where depID is your pattern and $$$ is the property value.
+
Enter a pattern using $$$ as the placeholder for the value of the property selected above.
+
For example, entering dept_$$$ might generate URIs with endings such as dept_Art or dept_Classics.