Commit 466aad85 authored by Bruno López Trigo's avatar Bruno López Trigo

Engadido formulario para construcción de clasificador

parent 8378a43d
......@@ -11,6 +11,13 @@ import brunolopez.expliclas.models.BuildParamsREP;
import brunolopez.expliclas.models.BuildParamsRT;
import brunolopez.expliclas.models.DatasetConfig;
import brunolopez.expliclas.models.SimpleMessage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
......@@ -31,6 +38,49 @@ public class BuilderService {
this.manager = new BuilderManagerImpl();
}
@Operation(
summary = "Build a classifier with J48 algorithm",
description = "Build a classifier with J48 algorithm",
responses = {
@ApiResponse(
responseCode = "201",
description = "Classifier successfuly build",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = DatasetConfig.class))
),
@ApiResponse(
responseCode = "400",
description = "Bad parameters format",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "409",
description = "Classifier already exists",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "404",
description = "Dataset not found",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "401",
description = "Unhauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
)
},
tags = "builder"
)
@SecurityRequirement(name = "token")
@POST
@Path("{dataset}/J48")
@Consumes(MediaType.APPLICATION_JSON)
......@@ -38,6 +88,7 @@ public class BuilderService {
@TokenNeeded
public Response buildClassifierJ48(@Context HttpHeaders httpheaders,
@Context UriInfo uriInfo,
@Parameter(description = "Dataset name")
@PathParam("dataset") String dataset,
BuildParamsJ48 params) {
......@@ -59,6 +110,49 @@ public class BuilderService {
}
@Operation(
summary = "Build a classifier with RandomTree algorithm",
description = "Build a classifier with RandomTree algorithm",
responses = {
@ApiResponse(
responseCode = "201",
description = "Classifier successfuly build",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = DatasetConfig.class))
),
@ApiResponse(
responseCode = "400",
description = "Bad parameters format",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "409",
description = "Classifier already exists",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "404",
description = "Dataset not found",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "401",
description = "Unhauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
)
},
tags = "builder"
)
@SecurityRequirement(name = "token")
@POST
@Path("{dataset}/RandomTree")
@Consumes(MediaType.APPLICATION_JSON)
......@@ -66,6 +160,7 @@ public class BuilderService {
@TokenNeeded
public Response buildClassifierRT(@Context HttpHeaders httpheaders,
@Context UriInfo uriInfo,
@Parameter(description = "Dataset name")
@PathParam("dataset") String dataset,
BuildParamsRT params) {
......@@ -87,6 +182,49 @@ public class BuilderService {
}
@Operation(
summary = "Build a classifier with REPTree algorithm",
description = "Build a classifier with RandomTree algorithm",
responses = {
@ApiResponse(
responseCode = "201",
description = "Classifier successfuly build",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = DatasetConfig.class))
),
@ApiResponse(
responseCode = "400",
description = "Bad parameters format",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "409",
description = "Classifier already exists",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "404",
description = "Dataset not found",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "401",
description = "Unhauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
)
},
tags = "builder"
)
@SecurityRequirement(name = "token")
@POST
@Path("{dataset}/REPTree")
@Consumes(MediaType.APPLICATION_JSON)
......@@ -94,6 +232,7 @@ public class BuilderService {
@TokenNeeded
public Response buildClassifierREP(@Context HttpHeaders httpheaders,
@Context UriInfo uriInfo,
@Parameter(description = "Dataset name")
@PathParam("dataset") String dataset,
BuildParamsREP params) {
......
package brunolopez.expliclas.services;
package brunolopez.expliclas.services;
import brunolopez.expliclas.datasets.DatasetManager;
import brunolopez.expliclas.datasets.DatasetManagerImpl;
......@@ -12,7 +12,6 @@ import brunolopez.expliclas.models.ModifiedDataset;
import brunolopez.expliclas.models.SimpleMessage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterStyle;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
......@@ -61,7 +60,8 @@ public class DatasetService {
schema = @Schema(implementation = SimpleMessage.class))
)
}
},
tags = "dataset"
)
@SecurityRequirement(name = "token")
@GET
......@@ -107,7 +107,8 @@ public class DatasetService {
schema = @Schema(implementation = SimpleMessage.class))
)
}
},
tags = "dataset"
)
@SecurityRequirement(name = "token")
@DELETE
......@@ -152,13 +153,15 @@ public class DatasetService {
schema = @Schema(implementation = SimpleMessage.class))
)
}
},
tags = "dataset"
)
@SecurityRequirement(name = "token")
@GET
@Path("{name}")
@Produces(MediaType.APPLICATION_JSON)
public Response getDataset(@Context HttpHeaders httpheaders,
@Parameter(description = "Dataset name")
@PathParam("name") String name) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
String token = "";
......@@ -182,7 +185,7 @@ public class DatasetService {
description = "Upload a new dataset",
responses = {
@ApiResponse(
responseCode = "200",
responseCode = "201",
description = "Dataset successfuly uploaded",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Dataset.class))
......@@ -216,7 +219,8 @@ public class DatasetService {
schema = @Schema(implementation = SimpleMessage.class))
)
}
},
tags = "dataset"
)
@SecurityRequirement(name = "token")
@POST
......@@ -225,8 +229,9 @@ public class DatasetService {
@Produces(MediaType.APPLICATION_JSON)
@TokenNeeded
public Response uploadDataset(@Context HttpHeaders httpheaders,
@Parameter(description = "Dataset name")
@PathParam("name") String name,
@Parameter(schema = @Schema(type = "string", format = "binary"), style = ParameterStyle.FORM)
@Parameter(schema = @Schema(type = "string", format = "binary", description = "Dataset file in arff format"))
@FormDataParam("file") InputStream uploadedInputStream) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
String token = header.substring("Bearer".length()).trim();
......@@ -245,12 +250,42 @@ public class DatasetService {
}
@Operation(
summary = "Delete a dataset",
description = "Delete a dataset",
responses = {
@ApiResponse(
responseCode = "200",
description = "Dataset successfuly deleted",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Dataset.class))
),
@ApiResponse(
responseCode = "404",
description = "Dataset couldn't be found",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "401",
description = "Unauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
)
},
tags = "dataset"
)
@SecurityRequirement(name = "token")
@DELETE
@Path("{name}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@TokenNeeded
public Response deleteDataset(@Context HttpHeaders httpheaders,
@Parameter(description = "Dataset name")
@PathParam("name") String name) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
......@@ -265,12 +300,50 @@ public class DatasetService {
}
@Operation(
summary = "Get a line",
description = "Get a line from specific dataset",
responses = {
@ApiResponse(
responseCode = "200",
description = "Line successfuly retrieved",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Line.class))
),
@ApiResponse(
responseCode = "400",
description = "Invalid line number",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "404",
description = "Dataset couldn't be found",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "401",
description = "Unauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
)
},
tags = "dataset"
)
@SecurityRequirement(name = "token")
@GET
@Path("{name}/{line}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getDatasetLine(@Context HttpHeaders httpheaders,
@Parameter(description = "Dataset name")
@PathParam("name") String name,
@Parameter(description = "Line number")
@PathParam("line") String line) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
......
......@@ -6,10 +6,16 @@ import brunolopez.expliclas.explainer.ExplainerManager;
import brunolopez.expliclas.explainer.ExplainerManagerImpl;
import brunolopez.expliclas.models.Classification;
import brunolopez.expliclas.models.Consequent;
import brunolopez.expliclas.models.DatasetConfig;
import brunolopez.expliclas.models.Dataset;
import brunolopez.expliclas.models.Explanation;
import brunolopez.expliclas.models.SimpleMessage;
import brunolopez.expliclas.models.VisualNode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import java.io.IOException;
import java.util.ArrayList;
import javax.ws.rs.Consumes;
......@@ -34,13 +40,59 @@ public class ExplainerService {
this.manager = new ExplainerManagerImpl();
}
@Operation(
summary = "Get global explanation",
description = "Get a general explanation of the classifier",
responses = {
@ApiResponse(
responseCode = "200",
description = "Explanation successfuly obtained",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Explanation.class))
),
@ApiResponse(
responseCode = "500",
description = "Error building explanation",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "404",
description = "Classifier not found",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "400",
description = "Bad request format",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "401",
description = "Unhauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
)
},
tags = "explainer"
)
@SecurityRequirement(name = "token")
@GET
@Path("{dataset}/{algorithm}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getGlobalExplanation(@Context HttpHeaders httpheaders,
@Parameter(description = "Dataset name")
@PathParam("dataset") String dataset,
@Parameter(description = "Algorithm name")
@PathParam("algorithm") String algorithm,
@Parameter(description = "Explanation language {en: english, es: spanish, gl: galician}")
@DefaultValue("en") @QueryParam("lang") String lang) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
......@@ -62,14 +114,61 @@ public class ExplainerService {
}
}
@Operation(
summary = "Get confusion explanation",
description = "Get confusion explanation between two consequents",
responses = {
@ApiResponse(
responseCode = "201",
description = "Explanation successfuly obtained",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Explanation.class))
),
@ApiResponse(
responseCode = "500",
description = "Error building explanation",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "404",
description = "Classifier not found",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "400",
description = "Bad consequents format",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "401",
description = "Unhauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
)
},
tags = "explainer"
)
@SecurityRequirement(name = "token")
@POST
@Path("{dataset}/{algorithm}/confusion")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getConfusionExplanation(@Context HttpHeaders httpheaders,
@Parameter(description = "Dataset name")
@PathParam("dataset") String dataset,
@Parameter(description = "Algorithm name")
@PathParam("algorithm") String algorithm,
@Parameter(description = "Consequents")
ArrayList<Consequent> consequents,
@Parameter(description = "Explanation language {en: english, es: spanish, gl: galician}")
@DefaultValue("en") @QueryParam("lang") String lang) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
......@@ -93,14 +192,61 @@ public class ExplainerService {
}
@Operation(
summary = "Get local explanation",
description = "Get an explanation about a specific classification",
responses = {
@ApiResponse(
responseCode = "201",
description = "Explanation successfuly obtained",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = Explanation.class))
),
@ApiResponse(
responseCode = "500",
description = "Error building explanation",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "404",
description = "Classifier not found",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "400",
description = "Bad classification format",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
),
@ApiResponse(
responseCode = "401",
description = "Unhauthorized",
content = @Content(mediaType = "application/json",
schema = @Schema(implementation = SimpleMessage.class))
)
},
tags = "explainer"
)
@SecurityRequirement(name = "token")
@POST
@Path("{dataset}/{algorithm}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getLocalExplanation(@Context HttpHeaders httpheaders,
@Parameter(description = "Dataset name")
@PathParam("dataset") String dataset,
@Parameter(description = "Algorithm name")
@PathParam("algorithm") String algorithm,
@Parameter(description = "Classifications")
ArrayList<Classification> classification,
@Parameter(description = "Explanation language {en: english, es: spanish, gl: galician}")
@DefaultValue("en") @QueryParam("lang") String lang) {
String header = httpheaders.getHeaderString(HttpHeaders.AUTHORIZATION);
......
......@@ -20,6 +20,7 @@ import io.swagger.v3.oas.annotations.security.OAuthFlows;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
......@@ -49,6 +50,28 @@ import javax.ws.rs.core.UriInfo;
@Server(
url = "http://localhost:8080/api"
)
},
tags = {
@Tag(
name = "session",
description = "Manage user's session"
),
@Tag(