Skip to content

Commit 62c8fa1

Browse files
committed
Json parallel corpora mode
1 parent a709031 commit 62c8fa1

File tree

8 files changed

+50
-27
lines changed

8 files changed

+50
-27
lines changed

src/components/DictionaryPropertiesModal/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const query = gql`
5858
}
5959
last_modified_at
6060
}
61-
user_blobs(data_type: "pdf", is_global: true) {
61+
user_blobs(data_type: ["pdf"], is_global: true) {
6262
id
6363
name
6464
data_type

src/ducks/dictImport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export const selectors = {
223223
});
224224

225225
case "LINKING":
226-
result &&= parallel
226+
result &&= parallel === "txt"
227227
? linking.size > 1
228228
: linking
229229
.toArray()

src/pages/CorpImport/Linker.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { pure } from "recompose";
44

55
import TranslationContext from "Layout/TranslationContext";
66

7-
function Columns({ blob, index, onDelete, onUpdateColumn }) {
7+
function Columns({ blob, index, mode, onDelete, onUpdateColumn }) {
88
const getTranslation = useContext(TranslationContext);
9-
const color = index ? "yellow" : "green";
10-
const name = index ? "sentence" : "base sentence";
9+
const color = (mode === 'json') ? "blue" : index ? "yellow" : "green";
10+
const name = (mode === 'json') ? "both sentences" : index ? "sentence" : "base sentence";
1111
const value = blob.getIn(["values", "sentence"], "dash");
1212
useEffect(() => { onUpdateColumn("sentence", value) }, []);
1313

@@ -20,7 +20,7 @@ function Columns({ blob, index, onDelete, onUpdateColumn }) {
2020
{getTranslation(name)}
2121
</Button>
2222
</div>
23-
{ !index && (
23+
{ !index && (mode === 'txt') && (
2424
<Checkbox className="blob-checkbox"
2525
label={getTranslation("Hide dashes")}
2626
onClick={() => onUpdateColumn("sentence", value === "dash" ? "dedash" : "dash", value)}
@@ -33,7 +33,12 @@ function Columns({ blob, index, onDelete, onUpdateColumn }) {
3333
function Linker({ blobs, state, onSelect, onDelete, onUpdateColumn }) {
3434
const getTranslation = useContext(TranslationContext);
3535

36-
const stateOptions = blobs.reduce(
36+
const first = state.first();
37+
const selected = first ? first.get("id").join("/") : null;
38+
const mode = first ? first.get("data_type") : null;
39+
40+
const stateOptions = blobs.filter(
41+
blob => (!mode || blob.get("data_type") === mode)).reduce(
3742
(acc, blob) => [
3843
...acc,
3944
{
@@ -45,9 +50,6 @@ function Linker({ blobs, state, onSelect, onDelete, onUpdateColumn }) {
4550
[]
4651
);
4752

48-
const first = state.first();
49-
const selected = first ? first.get("id").join("/") : null;
50-
5153
function onChange(event, data) {
5254
onSelect(data.value.split("/").map(x => parseInt(x, 10)));
5355
}
@@ -71,6 +73,7 @@ function Linker({ blobs, state, onSelect, onDelete, onUpdateColumn }) {
7173
key={id.join("/")}
7274
blob={v}
7375
index={i++}
76+
mode={mode}
7477
onDelete={onDelete}
7578
onUpdateColumn={onUpdateColumn(id)}
7679
/>

src/pages/CorpImport/index.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const fieldsQuery = gql`
3737
data_type
3838
data_type_translation_gist_id
3939
}
40-
user_blobs(data_type: "txt") {
40+
user_blobs(data_type: ["txt", "json"]) {
4141
id
4242
data_type
4343
name
@@ -46,7 +46,15 @@ export const fieldsQuery = gql`
4646
}
4747
`;
4848

49-
const convertMutation = gql`
49+
const convertJsonMutation = gql`
50+
mutation convertMutation($corpus_inf: CorpusInf!, $columns_inf: [ColumnInf]!) {
51+
convert_parallel_json(corpus_inf: $corpus_inf, columns_inf: $columns_inf) {
52+
triumph
53+
}
54+
}
55+
`;
56+
57+
const convertTxtMutation = gql`
5058
mutation convertMutation($corpus_inf: CorpusInf!, $columns_inf: [ColumnInf]!) {
5159
convert_plain_text(corpus_inf: $corpus_inf, columns_inf: $columns_inf) {
5260
triumph
@@ -95,7 +103,7 @@ class Info extends React.Component {
95103
data: { loading, error, user_blobs: blobs }
96104
} = this.props;
97105
if (!loading && !error) {
98-
const newBlobs = fromJS(blobs.filter(b => b.data_type === "txt")).map(v => v.set("values", new Map()));
106+
const newBlobs = fromJS(blobs).map(v => v.set("values", new Map()));
99107
// XXX: Ugly workaround
100108
if (JSON.stringify(this.props.blobs) !== JSON.stringify(newBlobs)) {
101109
this.props.setBlobs(newBlobs);
@@ -127,10 +135,6 @@ class Info extends React.Component {
127135
return (column, value, oldValue) => this.props.updateColumn(id, column, value, oldValue);
128136
}
129137

130-
onUpdateColumn(id) {
131-
return (column, value, oldValue) => this.props.updateColumn(id, column, value, oldValue);
132-
}
133-
134138
onSetLanguage(id) {
135139
return language => this.props.setLanguage(id, language);
136140
}
@@ -153,12 +157,13 @@ class Info extends React.Component {
153157
}
154158

155159
render() {
156-
const { step, isNextStep, blobs, linking, columnTypes, languages, licenses, locales, data } = this.props;
160+
const { step, isNextStep, blobs, linking, mode, columnTypes, languages, licenses, locales, data } = this.props;
157161

158162
if (data.loading || data.error) {
159163
return null;
160164
}
161165

166+
const mode_note = !!mode ? ` (${mode})` : "";
162167
const { all_fields: fields } = data;
163168
const fieldTypes = fromJS(fields).filter(field => field.get("data_type") === "Text");
164169
let i = 0;
@@ -167,7 +172,7 @@ class Info extends React.Component {
167172
<Step.Group widths={4}>
168173
<Step link active={step === "LINKING"} onClick={this.onStepClick("LINKING")}>
169174
<Step.Content>
170-
<Step.Title>{this.context("Parent Corpora")}</Step.Title>
175+
<Step.Title>{this.context("Parent Corpora") + mode_note.toUpperCase()}</Step.Title>
171176
<Step.Description>{this.context("Choose parallel corpora")}</Step.Description>
172177
</Step.Content>
173178
</Step>
@@ -261,7 +266,7 @@ class Info extends React.Component {
261266
</Button>
262267
) : step === "LINKING" ? (
263268
<Message style={{ margin: 0, textAlign: "center" }}>
264-
<Message.Content>{this.context("Choose at least two parent corpora.")}</Message.Content>
269+
<Message.Content>{this.context("Choose at least two txt corpora or one json file.")}</Message.Content>
265270
</Message>
266271
) : step === "COLUMNS" ? (
267272
<Message style={{ margin: 0, textAlign: "center" }}>
@@ -276,11 +281,16 @@ class Info extends React.Component {
276281
Info.contextType = TranslationContext;
277282

278283
function mapStateToProps(state) {
284+
285+
const linking = selectors.getLinking(state);
286+
const mode = linking.first() ? linking.first().get("data_type") : null;
287+
279288
return {
280289
step: selectors.getStep(state),
281-
isNextStep: selectors.getNextStep(state, true),
290+
isNextStep: selectors.getNextStep(state, mode),
282291
blobs: selectors.getBlobs(state),
283-
linking: selectors.getLinking(state),
292+
linking,
293+
mode,
284294
columnTypes: selectors.getColumnTypes(state),
285295
languages: selectors.getLanguages(state),
286296
licenses: selectors.getLicenses(state),
@@ -303,13 +313,15 @@ const mapDispatchToProps = {
303313

304314
Info.propTypes = {
305315
data: PropTypes.object,
306-
convert: PropTypes.func.isRequired,
316+
convertTxt: PropTypes.func.isRequired,
317+
convertJson: PropTypes.func.isRequired,
307318
licenses: PropTypes.object.isRequired,
308319
setLicense: PropTypes.func.isRequired
309320
};
310321

311322
export default compose(
312323
connect(mapStateToProps, mapDispatchToProps),
313324
graphql(fieldsQuery, { options: { fetchPolicy: "network-only" } }),
314-
graphql(convertMutation, { name: "convert" })
325+
graphql(convertTxtMutation, { name: "convertTxt" }),
326+
graphql(convertJsonMutation, { name: "convertJson" })
315327
)(Info);

src/pages/DialeqtImport.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import "pages/DictImport/styles.scss";
2828

2929
export const blobQuery = gql`
3030
query dialeqt_blobs {
31-
user_blobs(data_type: "dialeqt_dictionary") {
31+
user_blobs(data_type: ["dialeqt_dictionary"]) {
3232
id
3333
data_type
3434
name

src/pages/DictImport/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const fieldsQuery = gql`
3838
data_type
3939
data_type_translation_gist_id
4040
}
41-
user_blobs(data_type: "starling/csv") {
41+
user_blobs(data_type: ["starling/csv"]) {
4242
id
4343
data_type
4444
name

src/pages/Files/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class Files extends React.Component {
139139
case "txt":
140140
mimeType = ".txt";
141141
break;
142+
case "json":
143+
mimeType = ".json";
144+
break;
142145
case "image":
143146
mimeType = "image/*";
144147
break;
@@ -248,6 +251,11 @@ class Files extends React.Component {
248251
value: "txt",
249252
icon: "conversation"
250253
},
254+
{
255+
text: this.context("Json"),
256+
value: "json",
257+
icon: "conversation"
258+
},
251259
{
252260
text: this.context("Image"),
253261
value: "image",

src/pages/Map/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const dictionaryMapQuery = gql`
5959
location
6060
}
6161
}
62-
blobs: user_blobs(data_type: "pdf", is_global: true) {
62+
blobs: user_blobs(data_type: ["pdf"], is_global: true) {
6363
id
6464
data_type
6565
content

0 commit comments

Comments
 (0)