private void resolve(tokenGraphNode graph, ref WordnetSource wn_type, ref WordnetQueryType wn_qtype) { Boolean doResolve = false; if (wn_type == WordnetSource.none) { doResolve = true; } if (wn_qtype == WordnetQueryType.none) { doResolve = true; } if (!doResolve) { return; } if (graph.Count() == 0) { return; } var parentType = graph.type; var childType = graph?.getFirst()?.type; switch (childType) { case tokenGraphNodeType.symset_code: if (parentType == tokenGraphNodeType.word_srb) { wn_type = WordnetSource.serbian; wn_qtype = WordnetQueryType.getSymsetCodesByWord; } else { wn_type = WordnetSource.english; wn_qtype = WordnetQueryType.getSymsetCodesByWord; } break; case tokenGraphNodeType.word_eng: case tokenGraphNodeType.word_query: wn_type = WordnetSource.english; wn_qtype = WordnetQueryType.getWordsBySymsetCode; break; case tokenGraphNodeType.word_srb: wn_type = WordnetSource.serbian; wn_qtype = WordnetQueryType.getWordsBySymsetCode; break; } }
/// <summary> /// Queries by graph leaf child nodes and populates grand children /// </summary> /// <param name="graph">The graph.</param> /// <param name="scope">The scope.</param> /// <param name="side">The side.</param> /// <returns></returns> public tokenGraphNode queryByGraphNode(tokenGraphNode graph, apertiumDictQueryScope scope = apertiumDictQueryScope.startingWith, apertiumDictNeedleSide side = apertiumDictNeedleSide.native) { List <tokenGraphNode> nodes = graph.getAllLeafs().getTyped <tokenGraphNode>(); List <String> tokens = nodes.getNames(); var queryRes = query(tokens, scope, side); foreach (tokenGraphNode node in nodes) { if (side == apertiumDictNeedleSide.native) { node.AddKeyMatches(queryRes, tokenGraphNodeType.word_eng); } else { node.AddValueMatches(queryRes, tokenGraphNodeType.word_srb); } } /* * tokenGraphNodeType rType = tokenGraphNodeType.word_eng; * tokenGraphNodeType qType = tokenGraphNodeType.word_srb; * * if (graph.type == tokenGraphNodeType.word_query) * { * if (side == apertiumDictNeedleSide.english) * { * rType = tokenGraphNodeType.word_srb; * qType = tokenGraphNodeType.word_eng; * } * } else if (graph.type == tokenGraphNodeType.word_eng) * { * rType = tokenGraphNodeType.word_srb; * qType = tokenGraphNodeType.word_eng; * } * * * * graph.AddKeyValueChildren(queryRes, qType, rType, true); */ return(graph); }
/// <summary> /// Queries apropriate wordnet database according to graph node type. /// </summary> /// <param name="graph">The graph.</param> /// <param name="response">The response.</param> /// <returns></returns> public tokenGraphNode queryWithGraph(tokenGraphNode graph, ILogBuilder response, WordnetSource wn_type = WordnetSource.none, WordnetQueryType wn_qtype = WordnetQueryType.none) { resolve(graph, ref wn_type, ref wn_qtype); if (graph.Count() == 0) { return(graph); } List <IObjectWithPathAndChildren> leafs = graph.getAllLeafs(); var tokens = leafs.getNames(); wordnetSymsetResults res = null; switch (wn_type) { case WordnetSource.english: if (wn_qtype == WordnetQueryType.getSymsetCodesByWord) { res = query_eng(tokens, response); foreach (tokenGraphNode node in leafs) { node.AddValueMatches(res, tokenGraphNodeType.symset_code); } //graph.AddKeyValueChildren(res, tokenGraphNodeType.word_eng, tokenGraphNodeType.symset_code, true); } else { res = query_eng_symset(tokens, response); foreach (tokenGraphNode node in leafs) { node.AddKeyMatches(res, tokenGraphNodeType.word_eng); } //graph.AddKeyValueChildren(res, tokenGraphNodeType.symset_code, tokenGraphNodeType.word_eng); } break; case WordnetSource.serbian: if (wn_qtype == WordnetQueryType.getSymsetCodesByWord) { res = query_srb(tokens, response); foreach (tokenGraphNode node in leafs) { node.AddValueMatches(res, tokenGraphNodeType.symset_code); } //graph.AddKeyValueChildren(res, tokenGraphNodeType.word_srb, tokenGraphNodeType.symset_code, true); } else { res = query_srb_symset(tokens, response); foreach (tokenGraphNode node in leafs) { node.AddKeyMatches(res, tokenGraphNodeType.word_srb); } //graph.AddKeyValueChildren(res, tokenGraphNodeType.symset_code, tokenGraphNodeType.word_srb); } break; } ////var tokens = graph.getChildTokens(); //switch (childType) //{ // case tokenGraphNodeType.symset_code: // if (parentType == tokenGraphNodeType.word_srb) // { // var synonimres = query_srb_symset(tokens, response); // graph.AddKeyValueChildren(synonimres, tokenGraphNodeType.symset_code, tokenGraphNodeType.word_srb, true); // } else // { // var synonimres = query_eng_symset(tokens, response); // graph.AddKeyValueChildren(synonimres, tokenGraphNodeType.symset_code, tokenGraphNodeType.word_eng, true); // } // break; // case tokenGraphNodeType.word_eng: // case tokenGraphNodeType.word_query: // var coderes = query_eng(tokens, response); // graph.AddKeyValueChildren(coderes, tokenGraphNodeType.word_eng, tokenGraphNodeType.symset_code, true); // break; // case tokenGraphNodeType.word_srb: // var codesrbres = query_srb(tokens, response); // graph.AddKeyValueChildren(codesrbres, tokenGraphNodeType.word_srb, tokenGraphNodeType.symset_code, true); // break; //} return(graph); }