Skip to content

Commit

Permalink
Merge branch 'bruno'
Browse files Browse the repository at this point in the history
  • Loading branch information
bguil committed Jan 6, 2025
2 parents 3b2c5e8 + cea627e commit de018fc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
14 changes: 3 additions & 11 deletions src/components/sentence/FeaturesDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@
<script lang="ts">
import conllup from 'conllup';
import { mapState } from 'pinia';
import { replaceNewMetaText } from 'src/components/sentence/sentenceUtils';
import { useProjectStore } from 'src/pinia/modules/project';
import { sentence_bus_t, reactive_sentences_obj_t } from 'src/types/main_types';
import { reactive_sentences_obj_t, sentence_bus_t } from 'src/types/main_types';
import { PropType, defineComponent } from 'vue';
import AttributeTable from './AttributeTable.vue';
Expand Down Expand Up @@ -177,8 +178,6 @@ export default defineComponent({
},
methods: {
onFeatureDialogOk() {
const newMetaJson = this.sentenceBus.sentenceSVGs[this.userId].metaJson;
let oldText = this.sentenceBus.sentenceSVGs[this.userId].metaJson.text as string;
const oldForm = this.token.FORM;
this.token.FEATS = this.featTable.feat.reduce((obj, r) => {
Expand All @@ -196,14 +195,7 @@ export default defineComponent({
userId: this.userId,
});
if (oldForm !== this.token.FORM) {
newMetaJson.text = oldText.replace(oldForm, this.token.FORM);
this.sentenceBus.emit('tree-update:sentence', {
sentenceJson: {
metaJson: newMetaJson,
treeJson: this.sentenceBus.sentenceSVGs[this.userId].treeJson,
},
userId: this.userId,
});
replaceNewMetaText(this);
}
},
},
Expand Down
37 changes: 4 additions & 33 deletions src/components/sentence/TokensReplaceDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ import { replaceArrayOfTokens, tokenJson_T } from 'conllup/lib/conll';
import { reactive_sentences_obj_t, sentence_bus_t } from 'src/types/main_types';
import { PropType, defineComponent } from 'vue';
import { replaceNewMetaText } from 'src/components/sentence/sentenceUtils';
export default defineComponent({
name: 'TokensReplaceDialog',
emits: ['reload'],
Expand Down Expand Up @@ -190,39 +192,8 @@ export default defineComponent({
userId: this.userId,
});
this.$emit('reload');
this.replaceNewMetaText();
},
replaceNewMetaText() {
const newMetaJson = this.reactiveSentencesObj[this.userId].state.metaJson;
const newTree = this.reactiveSentencesObj[this.userId].state.treeJson;
const groupsJson = newTree.groupsJson;
const nodesJson = newTree.nodesJson;
const newForms = Object.values(nodesJson).map((node) => ({ form: node.FORM, spaceAfter: !node.MISC.SpaceAfter }));
let newMetaText = '';
let i = 0;
while (i < newForms.length) {
if (groupsJson[`${i + 1}-${i + 2}`]) {
newMetaText += groupsJson[`${i + 1}-${i + 2}`].FORM;
if (newForms[i + 2].spaceAfter) {
newMetaText += ' ';
}
i += 2;
} else {
newMetaText += newForms[i].form;
if (newForms[i].spaceAfter) {
newMetaText += ' ';
}
i += 1;
}
}
newMetaJson.text = newMetaText;
this.sentenceBus.emit('tree-update:sentence', {
sentenceJson: {
metaJson: newMetaJson,
treeJson: this.sentenceBus.sentenceSVGs[this.userId].treeJson,
},
userId: this.userId,
});
// this.replaceNewMetaText();
replaceNewMetaText(this);
},
},
});
Expand Down
41 changes: 41 additions & 0 deletions src/components/sentence/sentenceUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { sentence_bus_t, reactive_sentences_obj_t } from 'src/types/main_types';


export function replaceNewMetaText(data : { userId: string; sentenceBus: sentence_bus_t }) {
const newMetaJson = data.sentenceBus.sentenceSVGs[data.userId].metaJson;
const newTree = data.sentenceBus.sentenceSVGs[data.userId].treeJson;

const groupsFromFirstID = Object.fromEntries(
Object.entries(newTree.groupsJson).map(([key, value]) => {
const ids = key.split('-')
const newKey = ids[0]
const newValue = { 'end': Number(ids[1]), 'form': value.FORM, noSpaceAfter: value.MISC.SpaceAfter}
return [newKey, newValue];
})
);

let newMetaText = '';
let skip = -1; // set the upper bound of MWT, used to ignore inside regular tokens
let separator = ''; // store the separator for the next concatenation (avoid trailing whitespace)

Object.entries(newTree.nodesJson).forEach(([key, node]) => {
if (key in groupsFromFirstID) {
newMetaText += separator + groupsFromFirstID[key].form;
separator = (groupsFromFirstID[key].noSpaceAfter) ? '' : ' ';
skip = groupsFromFirstID[key].end;
} else {
if (Number(key) > skip) {
newMetaText += separator + node.FORM;
separator = (node.MISC.SpaceAfter === 'No') ? '' : ' ';
}
}
});
newMetaJson.text = newMetaText;
data.sentenceBus.emit('tree-update:sentence', {
sentenceJson: {
metaJson: newMetaJson,
treeJson: data.sentenceBus.sentenceSVGs[data.userId].treeJson,
},
userId: data.userId,
});
}

0 comments on commit de018fc

Please sign in to comment.