Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Customizable sentence parsing #1217

Merged
Merged
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
75 changes: 75 additions & 0 deletions ext/bg/css/settings2.css
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,81 @@ input.translation-text-replacement-test-output {
display: none;
}

.sentence-termination-character-list-table {
width: 100%;
table-layout: fixed;
border-spacing: 0.25em;
margin-top: 0.5em;
min-width: 400px;
}
.sentence-termination-character-list-table thead td {
white-space: nowrap;
font-size: var(--font-size-small);
line-height: 1;
text-align: left;
vertical-align: bottom;
font-weight: normal;
}
.sentence-termination-character-list-table td {
vertical-align: middle;
padding: 0;
}
.sentence-termination-character-list-table td:nth-child(1) {
width: 2em;
}
.sentence-termination-character-list-table td:nth-child(2) {
width: 4em;
}
.sentence-termination-character-list-table td:nth-child(3) {
width: 25%;
}
.sentence-termination-character-list-table td:nth-child(4) {
width: 18.5%;
}
.sentence-termination-character-list-table td:nth-child(5) {
width: 18.5%;
}
.sentence-termination-character-list-table td:nth-child(6) {
width: 40%;
}
.sentence-termination-character-list-table td:nth-child(7) {
width: 3em;
}
select.sentence-termination-character-type,
input.sentence-termination-character-input1,
input.sentence-termination-character-input2 {
width: 100%;
}
.sentence-termination-character-input2-alt {
text-align: center;
}
.sentence-termination-character-entry:not([data-type=quote]) .sentence-termination-character-input2 {
display: none;
}
.sentence-termination-character-entry[data-type=quote] .sentence-termination-character-input2-alt {
display: none;
}
.sentence-termination-character-include-list {
display: flex;
flex-flow: row nowrap;
}
.sentence-termination-character-include {
display: flex;
flex-flow: row nowrap;
white-space: nowrap;
align-items: center;
}
.sentence-termination-character-include>:first-child {
margin-right: 0.375em;
}
.sentence-termination-character-include+.sentence-termination-character-include {
margin-left: 1em;
}
#sentence-termination-character-list-empty {
flex: 0 1 auto;
margin-top: 0.5em;
}


/* Generic layouts */
.margin-above {
Expand Down
61 changes: 60 additions & 1 deletion ext/bg/data/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -846,13 +846,72 @@
"sentenceParsing": {
"type": "object",
"required": [
"scanExtent"
"scanExtent",
"enableTerminationCharacters",
"terminationCharacters"
],
"properties": {
"scanExtent": {
"type": "integer",
"minimum": 0,
"default": 200
},
"enableTerminationCharacters": {
"type": "boolean",
"default": true
},
"terminationCharacters": {
"type": "array",
"items": {
"type": "object",
"required": [
"enabled",
"character1",
"character2",
"includeCharacterAtStart",
"includeCharacterAtEnd"
],
"properties": {
"enabled": {
"type": "boolean",
"default": true
},
"character1": {
"type": "string",
"default": "\"",
"minLength": 1,
"maxLength": 1
},
"character2": {
"type": ["string", "null"],
"default": "\"",
"minLength": 1,
"maxLength": 1
},
"includeCharacterAtStart": {
"type": "boolean",
"default": false
},
"includeCharacterAtEnd": {
"type": "boolean",
"default": false
}
}
},
"default": [
{"enabled": true, "character1": "「", "character2": "」", "includeCharacterAtStart": false, "includeCharacterAtEnd": false},
{"enabled": true, "character1": "『", "character2": "』", "includeCharacterAtStart": false, "includeCharacterAtEnd": false},
{"enabled": true, "character1": "\"", "character2": "\"", "includeCharacterAtStart": false, "includeCharacterAtEnd": false},
{"enabled": true, "character1": "'", "character2": "'", "includeCharacterAtStart": false, "includeCharacterAtEnd": false},
{"enabled": true, "character1": ".", "character2": null, "includeCharacterAtStart": false, "includeCharacterAtEnd": true},
{"enabled": true, "character1": "!", "character2": null, "includeCharacterAtStart": false, "includeCharacterAtEnd": true},
{"enabled": true, "character1": "?", "character2": null, "includeCharacterAtStart": false, "includeCharacterAtEnd": true},
{"enabled": true, "character1": ".", "character2": null, "includeCharacterAtStart": false, "includeCharacterAtEnd": true},
{"enabled": true, "character1": "。", "character2": null, "includeCharacterAtStart": false, "includeCharacterAtEnd": true},
{"enabled": true, "character1": "!", "character2": null, "includeCharacterAtStart": false, "includeCharacterAtEnd": true},
{"enabled": true, "character1": "?", "character2": null, "includeCharacterAtStart": false, "includeCharacterAtEnd": true},
{"enabled": true, "character1": "…", "character2": null, "includeCharacterAtStart": false, "includeCharacterAtEnd": true}
]
}
}
}
Expand Down
19 changes: 18 additions & 1 deletion ext/bg/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,13 +684,30 @@ class OptionsUtil {
// Version 8 changes:
// Added translation.textReplacements.
// Moved anki.sentenceExt to sentenceParsing.scanExtent.
// Added sentenceParsing.enableTerminationCharacters.
// Added sentenceParsing.terminationCharacters.
for (const profile of options.profiles) {
profile.options.translation.textReplacements = {
searchOriginal: true,
groups: []
};
profile.options.sentenceParsing = {
scanExtent: profile.options.anki.sentenceExt
scanExtent: profile.options.anki.sentenceExt,
enableTerminationCharacters: true,
terminationCharacters: [
{enabled: true, character1: '「', character2: '」', includeCharacterAtStart: false, includeCharacterAtEnd: false},
{enabled: true, character1: '『', character2: '』', includeCharacterAtStart: false, includeCharacterAtEnd: false},
{enabled: true, character1: '"', character2: '"', includeCharacterAtStart: false, includeCharacterAtEnd: false},
{enabled: true, character1: '\'', character2: '\'', includeCharacterAtStart: false, includeCharacterAtEnd: false},
{enabled: true, character1: '.', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
{enabled: true, character1: '!', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
{enabled: true, character1: '?', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
{enabled: true, character1: '.', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
{enabled: true, character1: '。', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
{enabled: true, character1: '!', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
{enabled: true, character1: '?', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true},
{enabled: true, character1: '…', character2: null, includeCharacterAtStart: false, includeCharacterAtEnd: true}
]
};
delete profile.options.anki.sentenceExt;
}
Expand Down
Loading