Skip to content

Commit be32f62

Browse files
committed
Pre-marked corpora checkbox
1 parent 4bf1e95 commit be32f62

File tree

6 files changed

+75
-27
lines changed

6 files changed

+75
-27
lines changed

src/api/i18n.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@ export const stringsToTranslate = [
724724
"plural",
725725
"Possesiv",
726726
"posssesiv",
727+
"Pre-marked corpora",
727728
"precative",
728729
"predicative",
729730
"prefix",

src/ducks/dictImport.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const COLUMN_SET_TYPE = "@import/COLUMN_SET_TYPE";
1515
const LANGUAGE_SET = "@import/LANGUAGE_SET";
1616
const LICENSE_SET = "@import/LICENSE_SET";
1717
const LOCALE_SET = "@import/LOCALE_SET";
18+
const MARKED_SET = "@import/MARKED_SET";
1819

1920
function _getLinking(state) {
2021
return state.get("linking").filter(v => v.get("id"));
@@ -125,6 +126,23 @@ function updateColumnTypes(state) {
125126
});
126127
}
127128

129+
function setMarkedTxt(state) {
130+
const first = _getLinking(state).first();
131+
const firstId = first.get("id");
132+
const firstDataType = first.get("data_type");
133+
const isTxt = (firstDataType === "txt");
134+
const isMarked = (firstDataType === "marked");
135+
const statePath = ["linking", firstId, "data_type"];
136+
137+
return (
138+
isTxt
139+
? state.setIn(statePath, "marked")
140+
: isMarked
141+
? state.setIn(statePath, "txt")
142+
: state
143+
)
144+
}
145+
128146
const initial = new Map({
129147
step: "LINKING",
130148
blobs: new List(),
@@ -173,6 +191,9 @@ export default function (state = initial, { type, payload }) {
173191
case LICENSE_SET:
174192
newState = state.setIn(["licenses", payload.id], payload.license);
175193
break;
194+
case MARKED_SET:
195+
newState = setMarkedTxt(state);
196+
break;
176197
case LOCALE_SET:
177198
if (payload.value) {
178199
return state.setIn(["linking", payload.id, "translation", payload.locale], payload.value);
@@ -326,3 +347,7 @@ export function setTranslation(id, locale, value) {
326347
payload: { id, locale, value }
327348
};
328349
}
350+
351+
export function setMarked() {
352+
return { type: MARKED_SET };
353+
}

src/pages/CorpImport/Linker.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ function Columns({ blob, index, mode, onDelete, onUpdateColumn }) {
88
const getTranslation = useContext(TranslationContext);
99
const color = (mode === 'json') ? "blue" : index ? "yellow" : "green";
1010
const name = (mode === 'json') ? "both sides" : index ? "sentence" : "base sentence";
11-
const value = blob.getIn(["values", "sentence"], "dash");
12-
useEffect(
13-
() => {
14-
onUpdateColumn("sentence", value);
15-
if (mode === 'json') {
16-
onUpdateColumn("to_sentence", "json");
17-
}
18-
},
19-
[]
20-
);
11+
// We store 'dedash' flag in 'sentence' value because its value has no matter anywhere else
12+
const dedash = blob.getIn(["values", "sentence"], null) === "dedash";
13+
useEffect(() => {
14+
// On json format we have both sentences in one file,
15+
// so to_sentence is already selected, we store a random value there
16+
// to get 'Next Step' button active at once
17+
if (mode === 'json') {
18+
onUpdateColumn("to_sentence", "json_mode");
19+
}
20+
}, []);
2121

2222
return (
2323
<div className="blob blob_corp">
@@ -28,34 +28,37 @@ function Columns({ blob, index, mode, onDelete, onUpdateColumn }) {
2828
{getTranslation(name)}
2929
</Button>
3030
</div>
31-
{ !index && (mode === 'txt') && (
31+
{ !index && (mode === 'txt' || mode === 'marker') && (
3232
<Checkbox className="blob-checkbox"
3333
label={getTranslation("Hide dashes")}
34-
onClick={() => onUpdateColumn("sentence", value === "dash" ? "dedash" : "dash", value)}
35-
checked={value === "dedash"} />
34+
onClick={() => onUpdateColumn("sentence", dedash ? mode : "dedash")}
35+
checked={dedash} />
3636
) || <div className="blob-checkbox" />}
3737
</div>
3838
);
3939
}
4040

41-
function Linker({ blobs, state, onSelect, onDelete, onUpdateColumn }) {
41+
function Linker({ blobs, state, onSelect, onSetMarked, onDelete, onUpdateColumn }) {
4242
const getTranslation = useContext(TranslationContext);
4343

4444
const first = state.first();
45-
const selected = first ? first.get("id").join("/") : null;
45+
const firstId = first ? first.get("id") : null;
46+
const selected = firstId ? firstId.join("/") : null;
4647
const mode = first ? first.get("data_type") : null;
48+
const marked = (mode === 'marked');
4749

48-
const stateOptions = blobs.filter(
49-
blob => (!mode || blob.get("data_type") === mode)).reduce(
50-
(acc, blob) => [
51-
...acc,
50+
// Filtering stored files by type on mode current value
51+
// Note: 'marked' mode value means 'txt' files type
52+
const stateOptions = (
53+
blobs.filter(blob => !mode || blob.get("data_type") === (marked ? 'txt' : mode))
54+
).reduce((acc, blob) =>
55+
[ ...acc,
5256
{
5357
key: blob.get("id").join("/"),
5458
value: blob.get("id").join("/"),
5559
text: blob.get("name")
5660
}
57-
],
58-
[]
61+
], []
5962
);
6063

6164
function onChange(event, data) {
@@ -86,7 +89,17 @@ function Linker({ blobs, state, onSelect, onDelete, onUpdateColumn }) {
8689
onUpdateColumn={onUpdateColumn(id)}
8790
/>
8891
))
89-
.toArray()}
92+
.toArray()
93+
}
94+
{ (mode === 'txt' || mode === 'marked') && (
95+
<div className="container-gray">
96+
<Checkbox className="blob-checkbox"
97+
label={getTranslation(ff)}
98+
onClick={onSetMarked}
99+
checked={marked}
100+
/>
101+
</div>
102+
)}
90103
</div>
91104
);
92105
}

src/pages/CorpImport/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function corporaInfo({ linking, languages, licenses, mode }) {
3333

3434
function blobExport(blob, columnType) {
3535
const blob_id = blob.get("id").toArray();
36-
const dedash = (blob.getIn(["values", "sentence"], "dash") === "dedash");
36+
const dedash = (blob.getIn(["values", "sentence"], null) === "dedash");
3737
const field_ids = [columnType.get("sentence", new Map()).toArray(),
3838
columnType.get("to_sentence", new Map()).toArray()];
3939

src/pages/CorpImport/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {
1818
setLanguage,
1919
setLicense,
2020
setTranslation,
21-
updateColumn
21+
updateColumn,
22+
setMarked
2223
} from "ducks/dictImport";
2324
import TranslationContext from "Layout/TranslationContext";
2425
import LanguageSelection from "pages/DictImport/LanguageSelection";
@@ -72,7 +73,8 @@ class Info extends React.Component {
7273
updateColumn: PropTypes.func.isRequired,
7374
setColumnType: PropTypes.func.isRequired,
7475
setLanguage: PropTypes.func.isRequired,
75-
setTranslation: PropTypes.func.isRequired
76+
setTranslation: PropTypes.func.isRequired,
77+
setMarked: PropTypes.func.isRequired
7678
};
7779

7880
constructor(props) {
@@ -88,6 +90,7 @@ class Info extends React.Component {
8890
this.onSetLicense = this.onSetLicense.bind(this);
8991
this.onSetTranslation = this.onSetTranslation.bind(this);
9092
this.onSubmit = this.onSubmit.bind(this);
93+
this.onSetMarked = this.onSetMarked.bind(this);
9194
}
9295

9396
componentDidUpdate() {
@@ -107,6 +110,10 @@ class Info extends React.Component {
107110
this.props.linkingAdd(payload);
108111
}
109112

113+
onSetMarked() {
114+
this.props.setMarked();
115+
}
116+
110117
onDelete(payload) {
111118
this.props.linkingDelete(payload);
112119
}
@@ -196,6 +203,7 @@ class Info extends React.Component {
196203
blobs={blobs}
197204
state={linking}
198205
onSelect={this.onSelect}
206+
onSetMarked={this.onSetMarked}
199207
onDelete={this.onDelete}
200208
onUpdateColumn={this.onUpdateColumn}
201209
/>
@@ -301,7 +309,8 @@ const mapDispatchToProps = {
301309
setColumnType,
302310
setLanguage,
303311
setTranslation,
304-
setLicense
312+
setLicense,
313+
setMarked
305314
};
306315

307316
Info.propTypes = {

src/pages/DashboardRoute/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const DashboardRoute = connect(state => state.user)(({user}) => {
4747
<img className="card-item__img card-item__img_parallel-corpora" src={imageParallelCorpora} />
4848
</Link>
4949
{allowed_users.includes(user.id) && (
50-
<a className="card-item" href={window.location.origin + "/lingtrain_aligner/user/" + user.login}>
50+
<a className="card-item" href={window.location.origin + "/lingtrain_aligner/user/" + user.login + "/"}>
5151
<label className="card-item__label">{getTranslation("Lingtrain aligner")}</label>
5252
<img className="card-item__img card-item__img_parallel-corpora" src={imageParallelCorpora} />
5353
</a>

0 commit comments

Comments
 (0)