Skip to content

Commit

Permalink
Merge pull request #22 from ispras/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
nataliauvarova authored Sep 4, 2023
2 parents d49ac9b + 2ad509c commit 04588a9
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 23 deletions.
76 changes: 59 additions & 17 deletions src/components/CognateAnalysisModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,30 @@ const computeSwadeshAnalysisMutation = gql`
}
`;

const computeMorphCognateAnalysisMutation = gql`
mutation computeMorphCognateAnalysis(
$sourcePerspectiveId: LingvodocID!
$baseLanguageId: LingvodocID!
$groupFieldId: LingvodocID!
$perspectiveInfoList: [[LingvodocID]]!
) {
morph_cognate_analysis(
source_perspective_id: $sourcePerspectiveId
base_language_id: $baseLanguageId
group_field_id: $groupFieldId
perspective_info_list: $perspectiveInfoList
) {
triumph
result
xlsx_url
minimum_spanning_tree
embedding_2d
embedding_3d
perspective_name_list
}
}
`;

const SUGGESTIONS_PER_PAGE = 50;

function equalIds(id_a, id_b) {
Expand Down Expand Up @@ -293,6 +317,9 @@ class SLPerspectiveSelection extends React.Component {
} = this.props;


const xcr_label = mode.includes("morphology") ? "affix" : "transcription";
const xln_label = mode.includes("morphology") ? "meaning" : "translation";

return (
<div className="lingvo-cognate-sub-language" key={`perspective${index}`}>
<div key="check">
Expand Down Expand Up @@ -320,13 +347,13 @@ class SLPerspectiveSelection extends React.Component {
{perspectiveSelectionList[index] && (
<div className="lingvo-cognate-grid" key="selection">
<div className="lingvo-cognate-grid__name">
{this.context("Source transcription field")}:
{this.context("Source " + xcr_label + " field")}:
</div>
<div className="lingvo-cognate-grid__select">
<Select
disabled={!perspectiveSelectionList[index]}
defaultValue={transcriptionFieldIdStrList[index]}
placeholder={this.context("Source transcription field selection")}
placeholder={this.context("Source " + xcr_label + " field selection")}
options={textFieldsOptions}
onChange={(e, { value }) => {
transcriptionFieldIdStrList[index] = value;
Expand All @@ -336,12 +363,12 @@ class SLPerspectiveSelection extends React.Component {
className="lingvo-dropdown-select lingvo-dropdown-select_cognate"
/>
</div>
<div className="lingvo-cognate-grid__name">{this.context("Source translation field")}:</div>
<div className="lingvo-cognate-grid__name">{this.context("Source " + xln_label + " field")}:</div>
<div className="lingvo-cognate-grid__select">
<Select
disabled={!perspectiveSelectionList[index]}
defaultValue={translationFieldIdStrList[index]}
placeholder={this.context("Source translation field selection")}
placeholder={this.context("Source " + xln_label + " field selection")}
options={textFieldsOptions}
onChange={(e, { value }) => {
translationFieldIdStrList[index] = value;
Expand Down Expand Up @@ -1270,7 +1297,8 @@ class CognateAnalysisModal extends React.Component {
this.props.mode === "multi_analysis" ||
this.props.mode === "multi_reconstruction" ||
this.props.mode === "multi_suggestions" ||
this.props.mode === "multi_swadesh";
this.props.mode === "multi_swadesh" ||
this.props.mode === "multi_morphology";

(multi ? this.initialize_multi : this.initialize_single)();
}
Expand Down Expand Up @@ -1632,7 +1660,7 @@ class CognateAnalysisModal extends React.Component {
for (const field of textFields) {
const check_str = field.english_translation.toLowerCase();

if (!transcriptionFieldIdStr && check_str.includes("transcription")) {
if (!transcriptionFieldIdStr && (check_str.includes("transcription") || check_str.includes("affix"))) {
transcriptionFieldIdStr = id2str(field.id);
}

Expand Down Expand Up @@ -1684,7 +1712,8 @@ class CognateAnalysisModal extends React.Component {
this.props.mode === "multi_analysis" ||
this.props.mode === "multi_reconstruction" ||
this.props.mode === "multi_suggestions" ||
this.props.mode === "multi_swadesh"
this.props.mode === "multi_swadesh" ||
this.props.mode === "multi_morphology"
) {
this.state.groupFieldIdStr = value;

Expand Down Expand Up @@ -1874,6 +1903,16 @@ class CognateAnalysisModal extends React.Component {
});
}

handleMorphologyResult({ data: { morph_cognate_analysis }})
{
this.setState({
...morph_cognate_analysis,
/* Calculate plotly data */
...this.handleResult(morph_cognate_analysis),
computing: false
});
}

handleCognateResult({ data: { cognate_analysis }})
{
/* Initializing suggestions data, if required. */
Expand Down Expand Up @@ -1972,7 +2011,7 @@ class CognateAnalysisModal extends React.Component {
}

handleCreate() {
const { perspectiveId, computeCognateAnalysis, computeSwadeshAnalysis } = this.props;
const { perspectiveId, computeCognateAnalysis, computeSwadeshAnalysis, computeMorphCognateAnalysis } = this.props;

const groupField = this.fieldDict[this.state.groupFieldIdStr];

Expand All @@ -1985,7 +2024,8 @@ class CognateAnalysisModal extends React.Component {
this.props.mode === "multi_analysis" ||
this.props.mode === "multi_reconstruction" ||
this.props.mode === "multi_suggestions" ||
this.props.mode === "multi_swadesh"
this.props.mode === "multi_swadesh" ||
this.props.mode === "multi_morphology"
) {
for (const language of this.state.language_list) {
let p_count = 0;
Expand Down Expand Up @@ -2052,7 +2092,7 @@ class CognateAnalysisModal extends React.Component {
window.logger.err(this.context("Failed to launch cognate acoustic analysis!"));
}
);
} else if (this.props.mode === "swadesh") {
} else if (this.props.mode === "swadesh" || this.props.mode === "multi_swadesh") {
this.setState({ computing: true });
computeSwadeshAnalysis({
variables: {
Expand All @@ -2065,17 +2105,17 @@ class CognateAnalysisModal extends React.Component {
data => this.handleSwadeshResult(data),
error_data => this.handleError(error_data)
);
} else if (this.props.mode === "multi_swadesh") {
} else if (this.props.mode === "morphology" || this.props.mode === "multi_morphology") {
this.setState({ computing: true });
computeSwadeshAnalysis({
computeMorphCognateAnalysis({
variables: {
sourcePerspectiveId: perspectiveId,
baseLanguageId: this.baseLanguageId,
groupFieldId: groupField.id,
perspectiveInfoList: perspectiveInfoList,
}
}).then(
data => this.handleSwadeshResult(data),
data => this.handleMorphologyResult(data),
error_data => this.handleError(error_data)
);
} else {
Expand Down Expand Up @@ -2661,7 +2701,8 @@ class CognateAnalysisModal extends React.Component {
mode === "multi_analysis" ||
mode === "multi_reconstruction" ||
mode === "multi_suggestions" ||
mode === "multi_swadesh";
mode === "multi_swadesh" ||
mode === "multi_morphology";

const { language_list, perspectiveSelectionCountMap } = this.state;

Expand All @@ -2681,9 +2722,9 @@ class CognateAnalysisModal extends React.Component {
? this.context("Cognate reconstruction")
: mode === "suggestions"
? this.context("Cognate suggestions")
: mode === "swadesh"
: mode === "swadesh" || mode === "morphology"
? this.context("Glottochronology")
: mode === "multi_swadesh"
: mode === "multi_swadesh" || mode === "multi_morphology"
? this.context("Glottochronology multi-language")
: this.context("Cognate analysis")}
</Modal.Header>
Expand Down Expand Up @@ -2990,7 +3031,7 @@ class CognateAnalysisModal extends React.Component {
</div>
</div>
)}
{! /swadesh$/.test(mode) && (
{! /swadesh$/.test(mode) && ! /morphology$/.test(mode) && (
<div><pre>{this.state.result}</pre></div>
) || (
<div dangerouslySetInnerHTML={{ __html: this.state.result }}></div>
Expand Down Expand Up @@ -3021,6 +3062,7 @@ export default compose(
branch(({ visible }) => !visible, renderNothing),
graphql(computeCognateAnalysisMutation, { name: "computeCognateAnalysis" }),
graphql(computeSwadeshAnalysisMutation, { name: "computeSwadeshAnalysis" }),
graphql(computeMorphCognateAnalysisMutation, { name: "computeMorphCognateAnalysis" }),
graphql(connectMutation, { name: "connectGroup" }),
withApollo
)(CognateAnalysisModal);
8 changes: 7 additions & 1 deletion src/components/GroupingTagModal/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import TranslationContext from "Layout/TranslationContext";
import { searchQuery } from "./graphql";
import buildPartialLanguageTree from "./partialTree";
import Tree from "./Tree";
import { isEqual } from "lodash";

class SearchLexicalEntries extends React.Component {
constructor(props) {
super(props);

const { lexicalEntry } = props;
const entity = lexicalEntry.entities.find(e => e.content && e.content.length >= 2 && e.content.length < 8);
// field_id for 'Affix Meaning' is hardcoded here
// May be better to look for the field name and field id in cache
const aff_meaning_field_id = [66, 2042];
const aff_meaning = lexicalEntry.entities.find(e => e.content && isEqual(e.field_id, aff_meaning_field_id));
const some_entity = lexicalEntry.entities.find(e => e.content && e.content.length >= 2 && e.content.length < 8);
const entity = aff_meaning ? aff_meaning : some_entity;

this.state = {
searchString: entity ? entity.content.trim() : "",
Expand Down
14 changes: 9 additions & 5 deletions src/pages/Perspective/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ const toolsQuery = gql`
perspective(id: $id) {
id
english_status: status(locale_id: 2)
translations
created_by {
id
}
Expand Down Expand Up @@ -931,10 +932,13 @@ const Tools = ({
perspective: {
english_status,
created_by: { id: author_id },
edit_check
edit_check,
translations
}
} = data;

const titles = Object.values(translations)
const glottMode = titles.some(t => t.includes("Morpholog")) ? "morphology" : "swadesh";
const published = english_status === "Published" || english_status === "Limited access";

return (
Expand Down Expand Up @@ -982,12 +986,12 @@ const Tools = ({
)}
</Dropdown.Item>

<Dropdown.Item onClick={() => openCognateAnalysisModal(id, "swadesh")}>
{getTranslation("Glottochronology")}
<Dropdown.Item onClick={() => openCognateAnalysisModal(id, glottMode)}>
{getTranslation("Glottochronology (" + glottMode + ")")}
</Dropdown.Item>

<Dropdown.Item onClick={() => openCognateAnalysisModal(id, "multi_swadesh")}>
{getTranslation("Glottochronology multi-language")}
<Dropdown.Item onClick={() => openCognateAnalysisModal(id, "multi_" + glottMode)}>
{getTranslation("Glottochronology multi-language (" + glottMode + ")")}
</Dropdown.Item>
</>
)}
Expand Down

0 comments on commit 04588a9

Please sign in to comment.