work on NIHVIVO-205 ontology update
This commit is contained in:
parent
82dfc8d0ca
commit
d81d007a91
1 changed files with 25 additions and 4 deletions
|
@ -2,15 +2,24 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.ontology.update;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
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.Syntax;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
|
||||
|
@ -34,6 +43,8 @@ public class OntologyUpdater {
|
|||
private final String SUCCESS_RDF_FORMAT = "N3";
|
||||
private final String DIFF_FILE = DATA_DIR + "diff.tab.txt";
|
||||
|
||||
private final Log log = LogFactory.getLog(OntologyUpdater.class);
|
||||
|
||||
private ServletContext context;
|
||||
private OntModelSelector ontModelSelector;
|
||||
|
||||
|
@ -43,7 +54,7 @@ public class OntologyUpdater {
|
|||
this.ontModelSelector = ontModelSelector;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
public void update() throws IOException {
|
||||
// Check to see if the update is necessary.
|
||||
if (updateRequired()) {
|
||||
performUpdate();
|
||||
|
@ -84,7 +95,7 @@ public class OntologyUpdater {
|
|||
* Executes a SPARQL ASK query to determine whether the knowledge base
|
||||
* needs to be updated to conform to a new ontology version
|
||||
*/
|
||||
private boolean updateRequired() {
|
||||
private boolean updateRequired() throws IOException {
|
||||
String sparqlQueryStr = loadSparqlQuery(ASK_QUERY_FILE);
|
||||
if (sparqlQueryStr == null) {
|
||||
return false;
|
||||
|
@ -100,8 +111,18 @@ public class OntologyUpdater {
|
|||
* @param filePath
|
||||
* @return the query string or null if file not found
|
||||
*/
|
||||
private String loadSparqlQuery(String filePath) {
|
||||
return null; // TODO implement me!
|
||||
private String loadSparqlQuery(String filePath) throws IOException {
|
||||
File file = new File(context.getRealPath(filePath));
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
StringBuffer fileContents = new StringBuffer();
|
||||
String ln;
|
||||
while ((ln = reader.readLine()) != null) {
|
||||
fileContents.append(ln).append('\n');
|
||||
}
|
||||
return fileContents.toString();
|
||||
}
|
||||
|
||||
private void assertSuccess() {
|
||||
|
|
Loading…
Add table
Reference in a new issue