Skip to content

Commit

Permalink
Merge pull request rousakis#1 from rousakis/master
Browse files Browse the repository at this point in the history
Merged Commits from rousakis project
  • Loading branch information
rousakis committed Nov 19, 2015
2 parents 252e681 + 2774f52 commit 7ef370c
Show file tree
Hide file tree
Showing 70 changed files with 208 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Complex_Change": "Add Definition",
"Priority": 11.0,
"Complex_Change_Parameters": [
{
"subject": "1:ADD_PROPERTY_INSTANCE:-subject"
},
{
"definition": "1:ADD_PROPERTY_INSTANCE:-object"
}
],
"Simple_Changes": [
{
"Simple_Change": "ADD_PROPERTY_INSTANCE",
"Simple_Change_Uri": "1:ADD_PROPERTY_INSTANCE",
"Is_Optional": false,
"Selection_Filter": "1:ADD_PROPERTY_INSTANCE:-property = <http://www.ebi.ac.uk/efo/definition>",
"Mapping_Filter": "",
"Join_Filter": ""
}
]
}
22 changes: 22 additions & 0 deletions Change Definitions/ontological/EMBL/JSON definitions/Add Synonym
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Complex_Change": "Add Synonym",
"Priority": 13.0,
"Complex_Change_Parameters": [
{
"subject": "1:ADD_PROPERTY_INSTANCE:-subject"
},
{
"synonym": "1:ADD_PROPERTY_INSTANCE:-object"
}
],
"Simple_Changes": [
{
"Simple_Change": "ADD_PROPERTY_INSTANCE",
"Simple_Change_Uri": "1:ADD_PROPERTY_INSTANCE",
"Is_Optional": false,
"Selection_Filter": "1:ADD_PROPERTY_INSTANCE:-property = <http://www.ebi.ac.uk/efo/alternative_term>",
"Mapping_Filter": "",
"Join_Filter": ""
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Complex_Change": "Delete Definition",
"Priority": 12.0,
"Complex_Change_Parameters": [
{
"subject": "1:DELETE_PROPERTY_INSTANCE:-subject"
},
{
"definition": "1:DELETE_PROPERTY_INSTANCE:-object"
}
],
"Simple_Changes": [
{
"Simple_Change": "DELETE_PROPERTY_INSTANCE",
"Simple_Change_Uri": "1:DELETE_PROPERTY_INSTANCE",
"Is_Optional": false,
"Selection_Filter": "1:DELETE_PROPERTY_INSTANCE:-property = <http://www.ebi.ac.uk/efo/definition>",
"Mapping_Filter": "",
"Join_Filter": ""
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Complex_Change": "Delete Synonym",
"Priority": 14.0,
"Complex_Change_Parameters": [
{
"subject": "1:DELETE_PROPERTY_INSTANCE:-subject"
},
{
"synonym": "1:DELETE_PROPERTY_INSTANCE:-object"
}
],
"Simple_Changes": [
{
"Simple_Change": "DELETE_PROPERTY_INSTANCE",
"Simple_Change_Uri": "1:DELETE_PROPERTY_INSTANCE",
"Is_Optional": false,
"Selection_Filter": "1:DELETE_PROPERTY_INSTANCE:-property = <http://www.ebi.ac.uk/efo/alternative_term>",
"Mapping_Filter": "",
"Join_Filter": ""
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"Complex_Change": "Mark as Obsolete",
"Priority": 15.0,
"Complex_Change_Parameters": [
{
"obs_class": "1:ADD_SUPERCLASS:-subclass"
},
{
"reason": "2:ADD_PROPERTY_INSTANCE:-object"
}
],
"Simple_Changes": [
{
"Simple_Change": "ADD_SUPERCLASS",
"Simple_Change_Uri": "1:ADD_SUPERCLASS",
"Is_Optional": false,
"Selection_Filter": "1:ADD_SUPERCLASS:-superclass = <http://www.geneontology.org/formats/oboInOwl#ObsoleteClass>",
"Mapping_Filter": "",
"Join_Filter": ""
},
{
"Simple_Change": "ADD_PROPERTY_INSTANCE",
"Simple_Change_Uri": "2:ADD_PROPERTY_INSTANCE",
"Is_Optional": false,
"Selection_Filter": "2:ADD_PROPERTY_INSTANCE:-property = <http://www.ebi.ac.uk/efo/reason_for_obsolescence>",
"Mapping_Filter": "",
"Join_Filter": "2:ADD_PROPERTY_INSTANCE:-subject = 1:ADD_SUPERCLASS:-subclass"
}
]
}
10 changes: 0 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,11 @@
</properties>

<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/clients/TestChangeDetection.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import javax.ws.rs.core.MediaType;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

/**
*
Expand All @@ -23,13 +25,14 @@ public static void main(String[] args) {
String ip = "139.91.183.48";
ip = "localhost";
WebResource r = c.resource("http://" + ip + ":8181/ForthMaven-1.0/diachron/change_detection");
String input = "{ \"Old_Version\" : \"" + v1 + "\", "
+ "\"New_Version\" : \"" + v2 + "\", "
+ "\"Ingest\" : " + ingest + ", "
+ "\"Complex_Changes\" : [ ], "
+ "\"Associations\" : null"
+ "}";
ClientResponse response = r.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, input);
JSONObject input = new JSONObject();
input.put("Dataset_URI", "http://www.ebi.ac.uk/efo/");
input.put("Old_Version", v1);
input.put("New_Version", v2);
input.put("Ingest", ingest);
input.put("Complex_Changes", new JSONArray());
input.put("Associations", null);
ClientResponse response = r.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, input.toJSONString());
System.out.println(response.getEntity(String.class));
System.out.println(response.getStatus());
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/clients/TestDefineCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import javax.ws.rs.core.MediaType;
import org.json.simple.JSONObject;

/**
*
Expand All @@ -19,10 +20,11 @@ public static void main(String[] args) {
Client c = Client.create();
System.out.println("Testing Define CC Service...");
String ip = "139.91.183.48";
ip = "localhost";
// ip = "localhost";
String url = "http://" + ip + ":8181/ForthMaven-1.0/diachron/complex_change";
WebResource r = c.resource(url);
String input = "{ "

String ccDef = "{ "
+ "\"Complex_Change\" : \"Mark_as_Obsolete_v2\", "
+ "\"Priority\" : 1.0, "
+ "\"Complex_Change_Parameters\": ["
Expand Down Expand Up @@ -50,7 +52,11 @@ public static void main(String[] args) {
+ " ]"
+ "}";

ClientResponse response = r.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, input);
JSONObject input = new JSONObject();
input.put("Dataset_URI", "http://www.ebi.ac.uk/efo/");
input.put("CC_Definition", ccDef);

ClientResponse response = r.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, input.toJSONString());
System.out.println(response.getEntity(String.class));
System.out.println(response.getStatus());
System.out.println("-----\n");
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/clients/TestDeleteCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

/**
*
Expand All @@ -21,11 +23,14 @@ public static void main(String[] args) {
// test delete cc service
System.out.println("Testing Delete Service...");
String ip = "139.91.183.48";
ip = "localhost";
// ip = "localhost";
String url = "http://" + ip + ":8181/ForthMaven-1.0/diachron/complex_change";
String ccName = "Mark_as_Obsolete_v2";
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.putSingle("name", ccName);
params.putSingle("dataset_uri", "http://www.ebi.ac.uk/efo/");
WebResource r = c.resource(url);
ClientResponse response = r.path(ccName).accept(MediaType.APPLICATION_JSON).delete(ClientResponse.class);
ClientResponse response = r.queryParams(params).accept(MediaType.APPLICATION_JSON).delete(ClientResponse.class);
System.out.println(response.getEntity(String.class));
System.out.println(response.getStatus());
System.out.println("-----\n");
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/clients/TestInfoCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import javax.ws.rs.core.MediaType;

import javax.ws.rs.core.MultivaluedMap;
/**
*
* @author rousakis
Expand All @@ -23,9 +24,13 @@ public static void main(String[] args) {
String url = "http://" + ip + "/ForthMaven-1.0/diachron/complex_change";
WebResource r = c.resource(url);
String ccName = "Add Synonym";
ClientResponse response = r.path(ccName).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.putSingle("name", ccName);
params.putSingle("dataset_uri", "http://www.ebi.ac.uk/efo/");
ClientResponse response = r.queryParams(params).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
System.out.println(response.getEntity(String.class));
System.out.println(response.getStatus());
System.out.println("-----\n");

}
}
2 changes: 1 addition & 1 deletion src/main/java/clients/TestQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TestQuery {
public static void main(String[] args) {
Client c = Client.create();
String ip = "139.91.183.48:8181";
ip = "139.91.183.65:8080";
// ip = "139.91.183.65:8080";
System.out.println("Testing Query Service...");
String query = "select ?sc ?param_name ?param_value ?v1 ?v2 where { "
+ "?sc a co:Add_Label; "
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/services/change_detection/ChangeDetectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
*/
package services.change_detection;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
Expand All @@ -35,7 +32,6 @@
import org.diachron.detection.repositories.SesameVirtRep;
import org.diachron.detection.utils.ChangesDetector;
import org.diachron.detection.utils.ChangesManager;
import org.diachron.detection.utils.SCDUtils;
import utils.PropertiesManager;
import utils.Utils;

Expand All @@ -61,6 +57,7 @@ public ChangeDetectionImpl() {
* @param <b>inputMessage</b> : A JSON-encoded string which has the
* following form: <br>
* { <br>
* "Dataset_Uri" : "http://dataset", <br>
* "Old_Version" : "v1", <br>
* "New_Version" : "v2", <br>
* "Ingest" : true, <br>
Expand All @@ -69,6 +66,9 @@ public ChangeDetectionImpl() {
* } <br>
* where
* <ul>
* <li>Dataset_Uri - The URI of the dataset whose versions will be compared.
* If this parameter is missing from the JSON input message, then the URI
* will be taken from the properties file. <br>
* <li>Old_Version - The old version URI of a DIACHRON entity.<br>
* <li>New_Version - The old version URI of a DIACHRON entity.<br>
* <li>Ingest - A flag which denotes whether the service is called due to a
Expand Down Expand Up @@ -106,12 +106,16 @@ public Response changeDetectJSON(String inputMessage) {
JSONParser jsonParser = new JSONParser();
try {
JSONObject jsonObject = (JSONObject) jsonParser.parse(inputMessage);
if (jsonObject.size() != 5) {
String message = "JSON input message should have exactly 5 arguments.";
if (jsonObject.size() != 5 && jsonObject.size() != 6) {
String message = "JSON input message should have 5 or 6 arguments.";
String json = "{ \"Success\" : false, "
+ "\"Message\" : \"" + message + "\" }";
return Response.status(400).entity(json).build();
} else {
String datasetUri = (String) jsonObject.get("Dataset_URI");
if (datasetUri == null) {
datasetUri = propertiesManager.getPropertyValue("Dataset_URI");
}
String oldVersion = (String) jsonObject.get("Old_Version");
String newVersion = (String) jsonObject.get("New_Version");
boolean ingest = (Boolean) jsonObject.get("Ingest");
Expand All @@ -120,9 +124,7 @@ public Response changeDetectJSON(String inputMessage) {
if (oldVersion == null || newVersion == null || ccs == null) {
throw new ParseException(-1);
}
///
String datasetUri = propertiesManager.getPropertyValue("Dataset_URI");
String changesOntologySchema = propertiesManager.getPropertyValue("Changes_Ontology_Schema");
String changesOntologySchema = Utils.getDatasetSchema(datasetUri);
ChangesDetector detector = null;
try {
ChangesManager cManager = new ChangesManager(propertiesManager.getProperties(), datasetUri, oldVersion, newVersion, false);
Expand All @@ -135,6 +137,7 @@ public Response changeDetectJSON(String inputMessage) {
return Response.status(400).entity(json).build();
}
if (ingest) {
detector.detectAssociations(oldVersion, newVersion);
detector.detectSimpleChanges(oldVersion, newVersion, null);
}
String[] cChanges = {};
Expand Down Expand Up @@ -185,10 +188,8 @@ public Response changeDetectJSON(String inputMessage) {
@Produces(MediaType.APPLICATION_JSON)
public Response queryChangesOntologyGet(@QueryParam("query") String query,
@QueryParam("format") String format) {
Properties prop = new Properties();
OutputStream output = null;
try {
// prop.load(this.getClass().getResourceAsStream(propFile));
String ip = propertiesManager.getPropertyValue("Repository_IP");
String username = propertiesManager.getPropertyValue("Repository_Username");
String password = propertiesManager.getPropertyValue("Repository_Password");
Expand All @@ -198,7 +199,6 @@ public Response queryChangesOntologyGet(@QueryParam("query") String query,
query = query.replace(" where ", " from <" + changesOntol + "> ");
TupleQuery tupleQuery = sesame.getCon().prepareTupleQuery(QueryLanguage.SPARQL, query);
output = new OutputStream() {

private StringBuilder string = new StringBuilder();

@Override
Expand Down Expand Up @@ -292,8 +292,6 @@ public Response queryChangesOntologyPost(String inputMessage) {
if (format == null || query == null) {
throw new ParseException(-1);
}
///
// prop.load(this.getClass().getResourceAsStream(propFile));
String ip = propertiesManager.getPropertyValue("Repository_IP");
String username = propertiesManager.getPropertyValue("Repository_Username");
String password = propertiesManager.getPropertyValue("Repository_Password");
Expand Down
Loading

0 comments on commit 7ef370c

Please sign in to comment.