Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JJponciano committed Feb 27, 2024
1 parent 3cee3d7 commit c824d69
Show file tree
Hide file tree
Showing 8 changed files with 1,469 additions and 499 deletions.
Binary file modified .DS_Store
Binary file not shown.
758 changes: 720 additions & 38 deletions README.md

Large diffs are not rendered by default.

746 changes: 746 additions & 0 deletions documentations/Documentations.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,10 @@ public String sparqlQuery(@RequestBody SparqlQuery sq) {
System.out.println("Query:");
System.out.println(sq);
String query = KB.PREFIX + " " + sq.getResults();
// String triplestore = sq.getTriplestore();
String results;
// if (triplestore == null || triplestore.isBlank())
// results = Triplestore.get().executeSelectQuery(query);
// else
results = Triplestore.executeSelectQuery(query, GRAPHDB_QUERY_ENDPOINT);
System.out.println("***********" + "END /sparql-select" + "***********");

// System.out.println(results);
return results;
}

Expand All @@ -181,12 +176,6 @@ public ResponseEntity<Void> update(@RequestBody TripleOperation tripleOperation)
String subject = KB.sparqlValue(tripleData.getSubject());
String predicate = KB.sparqlValue(tripleData.getPredicate());
String object = KB.sparqlValue(tripleData.getObject());
// if (object.startsWith("http"))
// object = "<" + object + ">";
// if (predicate.startsWith("http"))
// predicate = "<" + predicate + ">";
// if (subject.startsWith("http"))
// subject = "<" + subject + ">";



Expand All @@ -203,82 +192,12 @@ public ResponseEntity<Void> update(@RequestBody TripleOperation tripleOperation)

Triplestore.executeUpdateQuery(query, GRAPHDB_UPDATE_ENDPOINT);

// // try to add until it is done
// boolean inprocess = true;
// while (inprocess) {
// try {
// update_model(tripleOperation, subject, predicate, object);
// Thread.sleep(100);
// inprocess = false;
// } catch (Exception e) {
// if (!e.getMessage().equals("Currently in an active transaction")) {
// inprocess = false;
// System.err.println(":::::::::::::::::ERROR:::::::::::::::::");
// System.err.println("DATA : " + tripleOperation);
// System.err.println(e.getMessage());
// System.err.println(":::::::::::::::::END ERROR:::::::::::::::::");
// }

// }
// }
return ResponseEntity.ok().build();
}

private void update_model(TripleOperation tripleOperation, String subject, String predicate, String object) {
if ("add".equalsIgnoreCase(tripleOperation.getOperation())) {
// Triplestore.get().addTriple(tripleData.getSubject(),
// tripleData.getPredicate(), tripleData.getObject());
// Insert a triple in graphdb

// String queryString = "SELECT ?type where { <" + tripleData.getPredicate()
// + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type }";
// String type = Triplestore.executeSelectQuery(queryString,
// GRAPHDB_QUERY_ENDPOINT);

// JSONObject jsonResult = new JSONObject(type);
// JSONObject resultsObject = jsonResult.getJSONObject("results");
// JSONArray bindings = resultsObject.getJSONArray("bindings");
// String predicateType = "";
// for (int i = 0; i < bindings.length(); i++) {
// JSONObject binding = bindings.getJSONObject(i);
// JSONObject predicateTypeObject = binding.getJSONObject("type");
// // System.out.println(predicateTypeObject.getString("value"));
// if
// (predicateTypeObject.getString("value").equals("http://www.w3.org/2002/07/owl#DatatypeProperty"))
// predicateType = predicateTypeObject.getString("value");
// }
// // bindings.length() > 1 ?
// // bindings.getJSONObject(1).getJSONObject("type").getString("value") :
// // bindings.getJSONObject(0).getJSONObject("type").getString("value");
// // System.out.println(tripleData.getPredicate()+" : "+predicateType);
// if (predicateType.equals("http://www.w3.org/2002/07/owl#DatatypeProperty")) {
// try {
// // TEST IF INT
// Integer.parseInt(object);
// object = "\"" + tripleData.getObject() + "\"^^xsd:integer";
// } catch (NumberFormatException e1) {
// try {
// // TEST IF FLOAT
// Float.parseFloat(object);
// object = "\"" + tripleData.getObject() + "\"^^xsd:float";
// } catch (NumberFormatException e2) {
// // IF STRING
// if (object.matches("\\d{4}-\\d{2}-\\d{2}.*")) {
// object = "\"" + tripleData.getObject() + "\"^^xsd:dateTime";
// System.out.println("MATCH TIME ----------------------------------");
// } else {
// object = "\"" + tripleData.getObject() + "\"^^xsd:string";
// }
// }
// }
// } else {
// if (object.matches("\\d{4}-\\d{2}-\\d{2}.*")) {
// object = "\"" + tripleData.getObject() + "\"^^xsd:dateTime";
// System.out.println("MATCH TIME ----------------------------------");
// } else {
// object = "<" + tripleData.getObject() + ">";
// }
// }


ParameterizedSparqlString insertCommand = new ParameterizedSparqlString();
insertCommand.setCommandText(KB.PREFIX + " INSERT DATA { " + subject + " " + predicate + " " + object + " }");
Expand All @@ -290,35 +209,6 @@ private void update_model(TripleOperation tripleOperation, String subject, Strin
System.out.println("-> added!");
} else if ("remove".equalsIgnoreCase(tripleOperation.getOperation())) {

// String queryString = "SELECT ?type where { <" + tripleData.getPredicate()
// + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type }";
// String type = Triplestore.executeSelectQuery(queryString,
// GRAPHDB_QUERY_ENDPOINT);

// JSONObject jsonResult = new JSONObject(type);
// JSONObject resultsObject = jsonResult.getJSONObject("results");
// JSONArray bindings = resultsObject.getJSONArray("bindings");
// String predicateType =
// bindings.getJSONObject(0).getJSONObject("type").getString("value");
// System.out.println(predicateType);
// if (predicateType == "http://www.w3.org/2002/07/owl#DatatypeProperty") {
// try {
// // TEST IF INT
// int intValue = Integer.parseInt(object);
// object = "\"" + tripleData.getObject() + "\"^^xsd:integer";
// } catch (NumberFormatException e1) {
// try {
// // TEST IF FLOAT
// float floatValue = Float.parseFloat(object);
// object = "\"" + tripleData.getObject() + "\"^^xsd:float";
// } catch (NumberFormatException e2) {
// // IF STRING
// object = "\"" + tripleData.getObject() + "\"^^xsd:string";
// }
// }
// } else {
// object = "<" + tripleData.getObject() + ">";
// }

ParameterizedSparqlString removeCommand = new ParameterizedSparqlString();
removeCommand.setCommandText(KB.PREFIX + " DELETE { " + subject + " " + predicate + " " + object + " }" +
Expand Down Expand Up @@ -411,39 +301,6 @@ public String downlift(GeoJsonForm di) {
}
}

/**
* Enriches the current ontology with another ontology if all classes and
* properties are known.
*
* @param file The ontology file to enrich the current ontology with.
* @return A JSON string with either a success message or a list of unknown
* classes and properties.
*
* Example: curl -X POST -F "file=@/path/to/your/ontology-file.ttl"
* "+KB.SERVER+":8081/api/enrich
*
*/
// @PostMapping("/enrich")
// public ResponseEntity<Void> enrich(@RequestParam("file") MultipartFile file)
// {
// // System.out.println("***********" + "/enrich" + "***********");

// // // store file
// // storageService.store(file);
// // // File reading
// // String filename = file.getOriginalFilename();
// // String filepath = KB.STORAGE_DIR + "/" + filename;
// // OntModel newOntology = ModelFactory.createOntologyModel();
// // try {
// // newOntology.read(new FileInputStream(filepath), null);
// // Triplestore.get().addOntology(newOntology);
// // return ResponseEntity.ok().build();
// // } catch (FileNotFoundException e) {
// // e.printStackTrace();
// // return ResponseEntity.badRequest().build();
// // }
// }

@PostMapping("/check-ontology")
public String check(@RequestParam("file") MultipartFile file) {
System.out.println("***********" + "/check-ontology" + "***********");
Expand All @@ -460,56 +317,6 @@ public String check(@RequestParam("file") MultipartFile file) {
String query = "INSERT DATA { " + enrichment.getTriples() + " }";
Triplestore.executeUpdateQuery(query, GRAPHDB_UPDATE_ENDPOINT);

// OntModel newOntology = ModelFactory.createOntologyModel();
// newOntology.read(new FileInputStream(filepath), null);

// StmtIterator stmtIterator = newOntology.listStatements();
// while (stmtIterator.hasNext()) {

// Statement statement = stmtIterator.nextStatement();
// Resource subject = statement.getSubject();
// Property predicate = statement.getPredicate();

// RDFNode object = statement.getObject();
// String p = predicate.getURI();
// // test if the predicate is knwown
// if (p.toLowerCase().contains("spalod")) {
// String query = KB.PREFIX + " SELECT ?s ?o WHERE {?s <" + p + "> ?o}";
// String result = Triplestore.executeSelectQuery(query,
// GRAPHDB_QUERY_ENDPOINT);
// try {
// ObjectMapper objectMapper = new ObjectMapper();
// JsonNode jsonNode = objectMapper.readTree(result);

// JsonNode bindingsNode = jsonNode.at("/results/bindings");
// boolean isEmpty = bindingsNode.isArray() && bindingsNode.isEmpty();
// String substring = p.substring(p.lastIndexOf("#") + 1, p.length());
// if (isEmpty) {
// unknownPredicates.add("spalod:" + substring);
// }

// } catch (Exception e) {
// e.printStackTrace();
// }
// }

// // add the statements

// OntProperty ontProperty = newOntology.getOntProperty(predicate.getURI());
// if (ontProperty.isObjectProperty()) {
// System.out.println(predicate + " is an object property.");
// } else if (ontProperty.isDatatypeProperty()) {
// System.out.println(predicate + " is a datatype property.");
// RDFDatatype dataType =
// ontProperty.getRange().as(OntResource.class).asLiteral().getDatatype();
// System.out.println("The datatype of " + predicate + " is " + dataType);
// }

// TripleOperation tripleOperation = new TripleOperation("add",
// new TripleData(subject.toString(), predicate.toString(), object.toString()));
// this.update(tripleOperation);

// }
String json = JsonUtil.setToJson(unknownPredicates);
System.out.println("***********" + "DONE: check-ontology" + "***********");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,86 +139,6 @@ public String datasetItems(@PathVariable String collectionId, @PathVariable Stri
// headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + res);
System.out.println("results: " + result);
return "/files/" + result;

// System.out.println("BBOX: " + bbox);
// // Get the item predicates
// String query, datetimeStart, datetimeEnd;
// query = "SELECT ?predicate WHERE {\n?dataset <"+KB.NS+"hasItem> ?item
// .\nFILTER(?dataset = <"+KB.NS+"" + datasetId + ">)\n?item ?predicate
// ?object\n}";
// System.out.println(query);
// // String query="SELECT ?object WHERE {?dataset <"+KB.NS+"hasItem> ?item .
// FILTER(?dataset = <"+KB.NS+"" + datasetId + ">) ?item ?predicate ?object .}";
// String results;
// results = Triplestore.get().executeSelectQuery(query);
// //System.out.println(results);
// JSONObject jsonResult = new JSONObject(results);
// JSONObject resultsObject = jsonResult.getJSONObject("results");
// JSONArray bindings = resultsObject.getJSONArray("bindings");
// String[] predicates = new String[bindings.length()];
// for (int i = 0; i < bindings.length(); i++) {
// JSONObject binding = bindings.getJSONObject(i);
// JSONObject predicate = binding.getJSONObject("predicate");
// predicates[i] = predicate.getString("value").split("#")[1];
// }

// // Get the item values
// query = "SELECT ?itemID ";
// for (int i = 0; i < predicates.length; i++) {

// try {
// query += "?" + URLDecoder.decode(predicates[i], "UTF-8").replace(" ",
// "").replace("-", "") + " ";
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// }
// query += "WHERE {\n?dataset <"+KB.NS+"hasItem> ?itemID .\nFILTER(?dataset =
// <"+KB.NS+"" + datasetId + ">)\n";
// if (datetime != null && !datetime.isEmpty()) {
// String[] datetimeRange = datetime.split("/");
// datetimeStart = datetimeRange[0];
// datetimeEnd = datetimeRange[1];
// System.out.println("DATETIME START: " + datetimeStart);
// System.out.println("DATETIME END: " + datetimeEnd);
// query += "?dataset <http://purl.org/dc/terms/issued> ?datetime .
// FILTER(?datetime >= \"" + datetimeStart +
// "\"^^<http://www.w3.org/2001/XMLSchema#dateTime> && ?datetime <= \"" +
// datetimeEnd + "\"^^<http://www.w3.org/2001/XMLSchema#dateTime>)\n";
// }
// for (int i = 0; i < predicates.length; i++) {
// try {
// query += "?itemID <"+KB.NS+"" + predicates[i] + "> ?" +
// URLDecoder.decode(predicates[i],"UTF-8").replace(" ", "").replace("-", "") +
// " .\n";
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// }

// // Filter by bbox
// if (bbox != null && !bbox.isEmpty()) {
// String[] bboxCoordinates = bbox.split(",");
// if (bboxCoordinates.length == 4) {
// String latitude1 = bboxCoordinates[0];
// String latitude2 = bboxCoordinates[1];
// String longitude1 = bboxCoordinates[2];
// String longitude2 = bboxCoordinates[3];

// query += "\nFILTER(?latitude >= " + latitude1 + " && ?latitude <= " +
// latitude2 +
// " && ?longitude >= " + longitude1 + " && ?longitude <= " + longitude2 + ")";
// }
// }

// query += "}";
// System.out.println(query);
// //results = Triplestore.get().executeSelectQuery(query);
// results = Triplestore.executeSelectQuery(query,
// "http://localhost:7200/repositories/Spalod");
// System.out.println("results:"+results);

// return results;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,7 @@
import java.util.ArrayList;

public class User {
// private String username;
// private String password;
// private List<String> roles;

// public User(String username,String password) {
// this.username = username;
// this.password = password;
// this.roles = new ArrayList<>();
// this.roles.add("USER");
// }

// @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
// public User(@JsonProperty("username") String _username,
// @JsonProperty("password") String _password,
// @JsonProperty("roles") List<String> _roles) {
// this.username = _username;
// this.password = _password;
// this.roles = _roles;
// }

// // Getters and setters
// public String getUsername() {
// return username;
// }

// public void setUsername(String username) {
// this.username = username;
// }

// @JsonIgnore
// public String getPassword() {
// return password;
// }

// @JsonProperty("password")
// public void setPassword(String password) {
// this.password = password;
// }

// public List<String> getRoles() {
// return roles;
// }

// public void setRoles(List<String> roles) {
// this.roles = roles;
// }


private String username;
private String password;
Expand Down
Loading

0 comments on commit c824d69

Please sign in to comment.