Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Aranda committed Jan 5, 2022
1 parent 70928b7 commit 41ef6c5
Show file tree
Hide file tree
Showing 8 changed files with 385 additions and 286 deletions.
105 changes: 59 additions & 46 deletions frontend/components/text-classifier/labeling-rules/RuleDefinition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,24 @@
<rule-empty-query :dataset="dataset" v-if="!query" />
<rule-labels-definition
v-else
:current-rule="currentRule"
:dataset="dataset"
@update-rule="updateRule"
@update-labels="updateLabels"
@save-rule="saveRule"
@update-rule="updateCurrentRule"
>
<template v-if="recordsMetric" #records-metric>
Records
<strong>
{{ recordsMetric.value }}
</strong>
</template>
</rule-labels-definition>
</div>
<div class="rule__metrics">
<rules-metrics
@records-metric="onUpdateRecordsMetric"
title="Rule Metrics"
metrics-type="all"
:activeLabel="activeLabel"
:key="refresh"
:rules="rules"
:dataset="dataset"
>
<template #button-bottom>
<re-button
class="rule__button button-quaternary--outline"
:disabled="isLoading"
@click="showRulesList"
>Manage rules</re-button
>
Expand All @@ -44,66 +36,87 @@
</div>
</template>
<script>
import { mapActions } from "vuex";
import { TextClassificationDataset } from "@/models/TextClassification";
export default {
props: {
dataset: {
type: Object,
default: () => ({}),
type: TextClassificationDataset,
required: true,
},
},
data: () => {
return {
rules: [],
selectedLabels: [],
currentRule: undefined,
recordsMetric: undefined,
activeLabel: undefined,
refresh: 0,
};
},
async fetch() {
await this.getAllRules();
this.currentRule = await this.getRule({
dataset: this.dataset,
query: this.query,
});
if (this.rules === undefined) {
await this.dataset.refreshRules();
}
if (!this.hasMetrics) {
await this.dataset.refreshRulesMetrics();
}
},
watch: {
async activeLabel(newValue) {
await this.updateCurrentRule({ query: this.query, label: newValue });
},
async query(newValue) {
await this.updateCurrentRule({
query: newValue,
label: this.activeLabel,
});
},
},
computed: {
query() {
return this.dataset.query.text;
},
activeLabel() {
return this.selectedLabels.length ? this.selectedLabels[0] : undefined;
isLoading() {
return this.$fetchState.pending;
},
},
watch: {
async query(n, o) {
if (o !== n) {
this.refresh++;
await this.$fetch();
}
currentRule() {
return this.dataset.getCurrentLabelingRule();
},
hasMetrics() {
return this.overalMetrics && this.rulesMetrics;
},
rules() {
return this.dataset.labelingRules;
},
overalMetrics() {
return this.dataset.labelingRulesOveralMetrics;
},
rulesMetrics() {
return this.dataset.labelingRulesMetrics;
},
},
methods: {
async getAllRules() {
this.rules = await this.getRules({ dataset: this.dataset });
async updateCurrentRule({ query, label, description }) {
if (!query) {
return await this.dataset.clearCurrentLabelingRule();
}
const rule = this.dataset.findRuleByQuery(query, label);
if (rule) {
await this.dataset.setCurrentLabelingRule(rule);
} else if (label) {
await this.dataset.setCurrentLabelingRule({
query,
label,
description: description || query,
});
} else {
await this.dataset.clearCurrentLabelingRule();
}
},
async showRulesList() {
await this.dataset.viewSettings.enableRulesSummary();
},
async updateRule() {
await this.$fetch();
},
updateLabels(labels) {
this.selectedLabels = labels;
},
onUpdateRecordsMetric(met) {
this.recordsMetric = met;
async saveRule(rule) {
await this.dataset.storeLabelingRule(rule);
},
...mapActions({
getRules: "entities/text_classification/getRules",
getRule: "entities/text_classification/getRule",
}),
},
};
</script>
Expand Down
Loading

0 comments on commit 41ef6c5

Please sign in to comment.