Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Add feature - visualization of text analaysis results and wo steps #209

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# create component failure classes from ordered steps and associate them with task executions
PREFIX cm: <http://onto.fel.cvut.cz/ontologies/csat-maintenance/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX termit: <http://onto.fel.cvut.cz/ontologies/application/termit/pojem/>
PREFIX : <http://onto.fel.cvut.cz/ontologies/csat/enhance-wo-text-0.1/>

DELETE{}
INSERT {
GRAPH cm:text-analysis-work-order-classes {
?taskExecutionIRI a ?componentFailureClass.
?componentFailureClass rdfs:subClassOf cm:component-failure--task .
}
} WHERE {
#SELECT ?taskExecutionIRI ?componentFailureClass {
{
SELECT ?taskExecutionIRI (GROUP_CONCAT(?componentFailureStep; separator=";") as ?componentFailureClassDiscrimitaor) {
{
SELECT ?taskExecutionIRI ?index ?componentFailureStep {
?taskExecutionIRI a cm:complex-execution;
rdf:type/rdfs:subClassOf cm:maintenance-work-order ;
# cm:is-part-of-workpackage ?workpackageIRI ;
cm:has-work-order-step ?taskStepExecutionIRI .

?taskStepExecutionIRI cm:described-finding ?finding .
?finding cm:has-failure-occurrence ?failureOccurrence .
?failureOccurrence termit:je-přiřazením-relace ?failureInstance.

?failureInstance :has-argument1 ?componentURI .
?failureInstance :has-argument2 ?failureURI .

FILTER (str(?componentURI) != "" && str(?failureURI) != "")

OPTIONAL{ ?taskStepExecutionIRI cm:step-index ?i . }
BIND(COALESCE(?i, "NO_INDEX") as ?index)
BIND(concat(str(?index), "-", str(?componentURI), str(?failureURI)) as ?componentFailureStep)
} ORDER BY ?taskExecutionIRI ?index
}
} GROUP BY ?taskExecutionIRI
}
BIND(IRI(concat(
"http://onto.fel.cvut.cz/ontologies/csat-maintenance/component-failure-class--",
MD5(?componentFailureClassDiscrimitaor)
)) as ?componentFailureClass
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# execution statistics of component failure classes extracted using text analysis
PREFIX cm: <http://onto.fel.cvut.cz/ontologies/csat-maintenance/>
PREFIX spif: <http://spinrdf.org/spif#>
PREFIX ofn: <http://www.ontotext.com/sparql/functions/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

DELETE{}
INSERT{
GRAPH cm:text-analysis-work-order-classes {
?componentFailureClass cm:min-work-time ?minWorkTime .
?componentFailureClass cm:max-work-time ?maxWorkTime .
?componentFailureClass cm:avg-work-time ?avgWorkTime .
?componentFailureClass cm:min-duration ?minDuration .
?componentFailureClass cm:max-duration ?maxDuration .
?componentFailureClass cm:avg-duration ?avgDuration .
}
}WHERE{
SELECT ?componentFailureClass (COUNT(*) as ?executionCount)
(MIN(?derivedWorkTime) as ?minWorkTime) (MAX(?derivedWorkTime) as ?maxWorkTime) (AVG(?derivedWorkTime) as ?avgWorkTime)
(MIN(?derivedDuration) as ?minDuration) (MAX(?derivedDuration) as ?maxDuration) (AVG(?derivedDuration) as ?avgDuration)
{

# query csat-data to get all annotated steps for a particular workpackage
{
SELECT ?taskExecutionIRI ?componentFailureClass
(MIN(?st) as ?derivedStart) (MAX(?et) as ?derivedEnd) (SUM(ofn:asMillis(?et - ?st))/1000.0/60.0/60.0 as ?derivedWorkTime) (ofn:asMillis(?derivedEnd - ?derivedStart)/1000.0/60.0/60.0 as ?derivedDuration)
{
?taskExecutionIRI a ?componentFailureClass.
?componentFailureClass rdfs:subClassOf cm:component-failure--task.

?session cm:is-part-of-maintenance-task ?taskExecutionIRI .

?session cm:start-date ?sDate.
?session cm:start-time ?sTime.
BIND(CONCAT(str(?sDate),"T", str(?sTime), IF(!contains(str(?sTime), "+"), "+02:00", "")) as ?start)

BIND(spif:parseDate(?start, "yyyy-MM-dd'T'HH:mm") as ?st)

?session cm:end-date ?eDate.
?session cm:end-time ?eTime.
BIND(CONCAT(str(?eDate),"T", str(?eTime), IF(!contains(str(?sTime), "+"), "+02:00", "")) as ?end)
BIND(spif:parseDate(?end, "yyyy-MM-dd'T'HH:mm") as ?et)

} GROUP BY ?taskExecutionIRI ?componentFailureClass
}
} GROUP BY ?componentFailureClass
}

Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package cz.cvut.kbss.amaplas.controller;

import cz.cvut.kbss.amaplas.model.AbstractEntity;
import cz.cvut.kbss.amaplas.model.Aircraft;
import cz.cvut.kbss.amaplas.persistence.dao.BaseDao;
import cz.cvut.kbss.amaplas.services.IdentifierService;
import cz.cvut.kbss.amaplas.util.Vocabulary;
import cz.cvut.kbss.jsonld.JsonLd;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.net.URI;
import java.util.List;
import java.util.Optional;

public class BaseController<E extends AbstractEntity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class SparqlDataReader {
public static final String ALL_TASKS = "/queries/analysis/all-tasks-strat-order.sparql";
public static final String TASK_CARDS_FROM_HISTORY = "/queries/analysis/task-cards-from-history.sparql";
public static final String TASK_TYPES_DEFINITIONS = "/queries/analysis/task-types-definitions.sparql";

public static final String TASK_STEP_AND_ANNOTATIONS = "/queries/analysis/task-step-and-annotations.sparql";
public static final String dateFormatPattern = "yyyy-MM-dd'T'HH:mm:ss";
public static final String dateFormatPattern1 = "yyyy-MM-dd'T'HH:mm:ssX";
public static final String dateFormatPattern2 = "dd.MM.yyyy'T'HH:mm";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ public class SparqlDataReaderRDF4J {

private static final Logger LOG = LoggerFactory.getLogger(SparqlDataReaderRDF4J.class);

public static <T> List<T> readData(String queryName, RepositoryConnection c, Map<String, Value> bindings, Function<BindingSet, T> converter){
String query = ResourceUtils.loadResource(queryName);
TupleQuery tupleQuery = c.prepareTupleQuery(query);
if(bindings != null)
bindings.entrySet().stream().forEach(b -> tupleQuery.setBinding(b.getKey(), b.getValue()));
TupleQueryResult rawResults = tupleQuery.evaluate();

List<T> results = new ArrayList<>();
while(rawResults.hasNext()){
BindingSet binding = rawResults.next();
T result = converter.apply(binding);
if(result != null)
results.add(result);
}
return results;
}

public List<String> readRowsAsStrings(String queryName, String endpoint, String username, String password) {
Repository r = RepositoryUtils.createRepo(endpoint, username, password);

Expand Down Expand Up @@ -223,10 +240,19 @@ public static <T> void optional(BindingSet bs, String name, Consumer<String> s){
.map(Value::stringValue)
.ifPresent(s);
}
public static <T> void optional(BindingSet bs, String name, Function<String, T> converter, Consumer<T> s){
Optional.ofNullable(bs.getValue(name))
.map(Value::stringValue)
.map(converter)
.ifPresent(s);
}

public static void mandatory(BindingSet bs, String name, Consumer<String> s){
s.accept(bs.getValue(name).stringValue());
}
public static <T> void mandatory(BindingSet bs, String name, Function<String, T> converter, Consumer<T> s){
s.accept(converter.apply(bs.getValue(name).stringValue()));
}

public static String manValue(BindingSet bs, String name){
return bs.getValue(name).stringValue();
Expand Down Expand Up @@ -344,6 +370,31 @@ public static Result convertToTimeLog(BindingSet bs, EntityRegistry registry) th
return t;
}


public static TaskStepPlan convertToTaskStepPlan(BindingSet bs){
TaskStepPlan taskStepPlan = new TaskStepPlan();
mandatory(bs, "step", URI::create, taskStepPlan::setEntityURI);
mandatory(bs, "task", URI::create, taskStepPlan::setParentTask);
optional(bs, "stepIndex", taskStepPlan::setStepIndex);
optional(bs, "workOrderText", taskStepPlan::setDescription);
optional(bs, "workOrderActionText", taskStepPlan::setActionDescription);

if(bs.hasBinding("annotatedText")){
FailureAnnotation failureAnnotation = new FailureAnnotation();
taskStepPlan.setFailureAnnotation(failureAnnotation);
optional(bs, "annotatedText", failureAnnotation::setAnnotatedText);
optional(bs, "componentUri", URI::create, failureAnnotation::setComponentUri);
optional(bs, "componentLabel", failureAnnotation::setComponentLabel);
optional(bs, "componentScore", Double::parseDouble, failureAnnotation::setComponentScore);
optional(bs, "failureUri", URI::create, failureAnnotation::setFailureUri);
optional(bs, "failureLabel", failureAnnotation::setFailureLabel);
optional(bs, "failureScore", Double::parseDouble, failureAnnotation::setFailureScore);
optional(bs, "aggregateScore", Double::parseDouble, failureAnnotation::setAggregateScore);
optional(bs, "isConfirmed", failureAnnotation::setConfirmed);
}
return taskStepPlan;
}

public static Pair<String, String> convertToPair(BindingSet bs) {
return Pair.of(manValue(bs, "tcId"), manValue(bs, "tcd"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,14 @@
import java.net.URI;
import java.util.Map;
import java.util.Set;

@MappedSuperclass
public class AbstractEntity implements Serializable {

// contains all types of the
@Types
protected Set<URI> types;

// property that specifies what is the main type of the entity. It also corresponds to a specific class from the object model

@OWLDataProperty(iri = Vocabulary.s_p_application_type)
protected String applicationType = this.getClass().getSimpleName();

@Id(generated = true)
protected URI entityURI;

@OWLDataProperty(iri = Vocabulary.s_p_id)
protected String id;

@OWLDataProperty(iri = Vocabulary.s_p_label)
protected String title;

@OWLDataProperty(iri = Vocabulary.s_p_description)
protected String description;

@Properties(fetchType = FetchType.EAGER)
protected Map<URI, Set<Object>> properties;

public Map<URI, Set<Object>> getProperties() {
return properties;
}

public void setProperties(Map<URI, Set<Object>> properties) {
this.properties = properties;
}

public Set<URI> getTypes() {
return types;
}
Expand All @@ -67,68 +39,32 @@ public void setEntityURI(URI entityURI) {
this.entityURI = entityURI;
}

public String getId(){
return id;
}

/**
* Utility method to convert id to string when it is passed as numeric value.
* @param id
*/
public void setId(Object id){
this.id = id == null ? null : id.toString();
}
public void setId(String id){
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@Override
public int hashCode() {
if(getEntityURI() == null)
if (getEntityURI() == null)
return super.hashCode();
return getEntityURI().hashCode();
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if(obj == null)
if (obj == null)
return false;

if(!(obj instanceof AbstractEntity))
if (!(obj instanceof AbstractEntityWithDescription))
return false;

if(getEntityURI() == null)
if (getEntityURI() == null)
return super.equals(obj);

return getEntityURI().equals(((AbstractEntity)obj).getEntityURI());
return getEntityURI().equals(((AbstractEntityWithDescription) obj).getEntityURI());
}

@Override
public String toString() {
return applicationType + "{" +
"types=" + types +
", entityURI=" + entityURI +
", id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", properties=" + properties +
return "AbstractEntity{" +
"entityURI=" + entityURI +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cz.cvut.kbss.amaplas.model;

import cz.cvut.kbss.amaplas.util.Vocabulary;
import cz.cvut.kbss.jopa.model.annotations.*;

import java.io.Serializable;
import java.net.URI;
import java.util.Map;
import java.util.Set;

@MappedSuperclass
public class AbstractEntityWithDescription extends AbstractEntity {

// property that specifies what is the main type of the entity. It also corresponds to a specific class from the object model

@OWLDataProperty(iri = Vocabulary.s_p_id)
protected String id;

@OWLDataProperty(iri = Vocabulary.s_p_label)
protected String title;

@OWLDataProperty(iri = Vocabulary.s_p_description)
protected String description;
@Properties(fetchType = FetchType.EAGER)
protected Map<URI, Set<Object>> properties;

public Map<URI, Set<Object>> getProperties() {
return properties;
}

public void setProperties(Map<URI, Set<Object>> properties) {
this.properties = properties;
}


public String getId(){
return id;
}

/**
* Utility method to convert id to string when it is passed as numeric value.
* @param id
*/
public void setId(Object id){
this.id = id == null ? null : id.toString();
}
public void setId(String id){
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

@Override
public String toString() {
return applicationType + "{" +
"types=" + types +
", entityURI=" + entityURI +
", id=" + id +
", title='" + title + '\'' +
", description='" + description + '\'' +
", properties=" + properties +
'}';
}
}
Loading