Commit b7b30100 authored by schrieveslaach's avatar schrieveslaach

Improve code

parent da6b5325
Pipeline #37931037 passed with stages
in 34 minutes and 4 seconds
......@@ -4,6 +4,10 @@
- Upgrade DKPro Core to 1.10.0
- Upgrade dependencies
## nlp-sonarqube-plugin
- Add SonarQube plugin. Fixes #12.
## nlp-machen-plugin
- Fixes #31
......
......@@ -325,7 +325,7 @@ cd nlp-sonarqube-plugin
mvn clean package
docker run --rm -it \
-p 9000:9000 -p 9092:9092 \
-v $(pwd)/target/nlp-sonarqube-plugin-1.0-SNAPSHOT.jar:/opt/sonarqube/extensions/plugins/nlp-sonarqube-plugin-1.0-SNAPSHOT.jar \
-v $(pwd)/target/nlp-sonarqube-plugin-<NLPf version>.jar:/opt/sonarqube/extensions/plugins/nlp-sonarqube-plugin.jar \
sonarqube:6.7-alpine
```
......
......@@ -50,7 +50,6 @@ import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.XMLInputSource;
import org.apache.uima.util.XMLParser;
import org.springframework.core.annotation.AnnotationUtils;
import javax.inject.Inject;
import java.io.File;
......@@ -61,14 +60,12 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.stream.Collectors;
import static org.apache.uima.fit.util.JCasUtil.select;
import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
......
......@@ -38,7 +38,6 @@ import org.apache.uima.collection.CollectionReaderDescription;
import org.apache.uima.fit.descriptor.ResourceMetaData;
import org.apache.uima.fit.descriptor.TypeCapability;
import org.apache.uima.jcas.JCas;
import org.springframework.core.annotation.AnnotationUtils;
import java.io.File;
import java.io.FileOutputStream;
......
......@@ -48,7 +48,6 @@ import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.util.CasCopier;
import org.springframework.core.annotation.AnnotationUtils;
import java.io.File;
import java.io.FileOutputStream;
......
......@@ -86,7 +86,7 @@ public class TestResult implements Comparable<TestResult> {
@Override
public String toString() {
return measures.stream()
.map(measure -> measure.getAnalysisEngineName())
.map(Measure::getAnalysisEngineName)
.distinct()
.collect(Collectors.joining(", "));
}
......
......@@ -37,6 +37,10 @@ export function stringToColor(str) {
return Color(color);
}
function abbreviateClassname(className) {
return className.substring(className.lastIndexOf('.') + 1);
}
function paintDataSetBasedOnLabelString(dataSet) {
let color = stringToColor(dataSet.label);
dataSet.backgroundColor = color.hsl().string();
......@@ -68,7 +72,7 @@ export function findTokenHistory(project) {
}
export function findNlpPipelinePerformanceDataSets(project, dataSetConfiguration) {
return getJSON('/api/measures/search_history?component=' + project.key + '&metrics=annotations').then(function (response) {
return getJSON(`/api/measures/search_history?component=${project.key}&metrics=annotations`).then(function (response) {
const annotationsHistory = response.measures[0].history;
const annotations = new Set();
......@@ -79,11 +83,12 @@ export function findNlpPipelinePerformanceDataSets(project, dataSetConfiguration
}
const dataSets = [];
annotations.forEach(function (annotation) {
annotations.forEach(annotation => {
let dataSet = {
...dataSetConfiguration,
label: annotation,
label: abbreviateClassname(annotation),
annotationClassName: annotation,
yAxisID: 'measures',
data: [],
fill: false
......@@ -99,23 +104,22 @@ export function findNlpPipelinePerformanceDataSets(project, dataSetConfiguration
let promises = [];
// Loads for each dataSet the time series of F-measures
dataSets.forEach(function (dataSet) {
promises.push(findBestPerformingPipelineFMeasure(project, dataSet.label).then((fMeasureHistoryData) => {
dataSet.data = fMeasureHistoryData;
return dataSet;
}).catch(err => {
console.log(err);
}));
dataSets.forEach(dataSet => {
promises.push(findBestPerformingPipelineFMeasure(project, dataSet.annotationClassName)
.then((fMeasureHistoryData) => {
dataSet.data = fMeasureHistoryData;
return dataSet;
}).catch(err => {
console.log(err);
}));
});
return Promise.all(promises).then((values) => {
return values.filter(data => data !== undefined);
});
return Promise.all(promises).then(values => values.filter(data => data !== undefined));
});
}
function findBestPerformingPipelineFMeasure(project, annotation) {
return getJSON('/api/measures/search_history?component=' + project.key + '&metrics=' + annotation).then(function (response) {
return getJSON(`/api/measures/search_history?component=${project.key}&metrics=${annotation}`).then(response => {
if (response.errors !== undefined) {
return [];
}
......@@ -140,88 +144,89 @@ function findBestPerformingPipelineFMeasure(project, annotation) {
}
//History date format: YYYY-MM-DDTHH:mm:ssZ
fMeasureHistoryChartJsData.sort(function (a, b) {
return new Date(b.x) - new Date(a.x);
});
fMeasureHistoryChartJsData.sort((a, b) => new Date(b.x) - new Date(a.x));
return fMeasureHistoryChartJsData;
});
}
export function findNerHeatmapData(project) {
return getJSON('/api/measures/component?component=' + project.key + '&metricKeys=named-entity-variants').then(function (response) {
if (response.errors !== undefined) {
return [];
}
return JSON.parse(response.component.measures[0].value);
}).then((namedEntityQuantities) => {
return getJSON('/api/measures/component?component=' + project.key + '&metricKeys=de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity').then(function (response) {
let fScores = JSON.parse(response.component.measures[0].value);
namedEntityQuantities.forEach((ne) => {
fScores.forEach((fScore) => {
if (ne["f-measure"] === undefined && fScore.variant === ne.variant) {
ne["f-measure"] = fScore["f-measure"];
}
})
});
return getJSON(`/api/measures/component?component=${project.key}&metricKeys=named-entity-variants`)
.then(response => {
if (response.errors !== undefined) {
return [];
}
return {
name: "NER Heatmap",
children: namedEntityQuantities
};
return JSON.parse(response.component.measures[0].value);
}).then((namedEntityQuantities) => {
return getJSON(`/api/measures/component?component=${project.key}&metricKeys=de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity`)
.then(response => {
let fScores = JSON.parse(response.component.measures[0].value);
namedEntityQuantities.forEach(ne => {
fScores.forEach(fScore => {
if (ne["f-measure"] === undefined && fScore.variant === ne.variant) {
ne["f-measure"] = fScore["f-measure"];
}
})
});
return {
name: "NER Heatmap",
children: namedEntityQuantities
};
});
});
});
}
export function findIsolatedToolsTestData(project) {
return getJSON('/api/measures/component?component=' + project.key + '&metricKeys=isolated-tools-test-data').then(response => {
if (response.errors !== undefined) {
return [];
}
let toolsTestData = JSON.parse(response.component.measures[0].value);
let toLabel = function (nlpToolMeasure) {
if (nlpToolMeasure.variant === null) {
return nlpToolMeasure.outputType;
return getJSON(`/api/measures/component?component=${project.key}&metricKeys=isolated-tools-test-data`)
.then(response => {
if (response.errors !== undefined) {
return [];
}
return nlpToolMeasure.outputType + " - " + nlpToolMeasure.variant;
}
const data = {};
const annotations = new Set();
toolsTestData.forEach(d => {
d.measures.forEach(m => {
annotations.add(toLabel(m));
});
});
let toolsTestData = JSON.parse(response.component.measures[0].value);
data.labels = Array.from(annotations);
const toLabel = function (nlpToolMeasure) {
if (nlpToolMeasure.variant === null) {
return abbreviateClassname(nlpToolMeasure.outputType);
}
return `${abbreviateClassname(nlpToolMeasure.outputType)}${nlpToolMeasure.variant}`;
};
let dataSets = {};
toolsTestData.forEach(d => {
d.measures.forEach(m => {
const data = {};
const annotations = new Set();
toolsTestData.forEach(d => {
d.measures.forEach(m => {
annotations.add(toLabel(m));
});
});
let dataSet = dataSets[m.analysisEngineName];
if (dataSet === undefined) {
dataSet = {
label: m.analysisEngineName,
backgroundColor: stringToColor(m.analysisEngineName).hsl().string(),
data: new Array(data.labels.length)
data.labels = Array.from(annotations);
let dataSets = {};
toolsTestData.forEach(d => {
d.measures.forEach(m => {
let dataSet = dataSets[m.analysisEngineName];
if (dataSet === undefined) {
dataSet = {
label: m.analysisEngineName,
backgroundColor: stringToColor(m.analysisEngineName).hsl().string(),
data: new Array(data.labels.length)
}
paintDataSetBasedOnLabelString(dataSet);
dataSets[m.analysisEngineName] = dataSet;
}
paintDataSetBasedOnLabelString(dataSet);
dataSets[m.analysisEngineName] = dataSet;
}
let i = data.labels.indexOf(toLabel(m));
dataSet.data[i] = m["f-measure"];
let i = data.labels.indexOf(toLabel(m));
dataSet.data[i] = m["f-measure"];
});
});
});
data.datasets = Object.keys(dataSets).map(k => dataSets[k]);
data.datasets = Object.keys(dataSets).map(k => dataSets[k]);
return data;
});
return data;
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment