Skip to content

Commit

Permalink
Labojumi pārtaisītajās redukcijās.
Browse files Browse the repository at this point in the history
  • Loading branch information
lauma committed Apr 10, 2019
1 parent b758124 commit 7128e3f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lv.ailab.lvtb.universalizer.pml.PmlANode;
import lv.ailab.lvtb.universalizer.pml.utils.PmlANodeListUtils;
import lv.ailab.lvtb.universalizer.transformator.morpho.AnalyzerWrapper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -739,17 +740,20 @@ public boolean splitMorphoEllipsis(String idPostfix)
if (reductionField == null || reductionField.isEmpty()) return false;
try
{
XmlDomANode parentToAppend = getParent();
if (!parentToAppend.isPhraseNode()) parentToAppend = this;
Document ownerDoc = domNode.getOwnerDocument();
// Children container
Node childenNode = (Node) XPathEngine.get().evaluate(
"./children", domNode, XPathConstants.NODE);
"./children", parentToAppend.domNode, XPathConstants.NODE);
if (childenNode == null)
{
childenNode = domNode.getOwnerDocument().createElement("children");
domNode.appendChild(childenNode);
childenNode = ownerDoc.createElement("children");
parentToAppend.domNode.appendChild(childenNode);
}

// Node itself
Element newTokenNode = domNode.getOwnerDocument().createElement("node");
Element newTokenNode = ownerDoc.createElement("node");
childenNode.appendChild(newTokenNode);

// id attribute
Expand All @@ -769,9 +773,9 @@ public boolean splitMorphoEllipsis(String idPostfix)
newTokenNode.appendChild(ord);

// Role.
Node roleNode = domNode.getOwnerDocument().createElement("role");
Node roleNode = ownerDoc.createElement("role");
newTokenNode.appendChild(roleNode);
roleNode.appendChild(domNode.getOwnerDocument().createTextNode(LvtbRoles.ELLIPSIS_TOKEN));
roleNode.appendChild(ownerDoc.createTextNode(LvtbRoles.ELLIPSIS_TOKEN));

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ protected HashMap<String, HashSet<String>> getGov2subj(PmlANode aNode, HashMap<S
&& ((phrasePart.getM() != null && MorphoTransformator.isTrueAux(phrasePart.getM().getLemma()))
|| MorphoTransformator.isTrueAux(phrasePart.getReductionLemma())))
continue;
// Do not add coordination conjuctions and punctuation.
if (LvtbCoordTypes.CRDPARTS.equals(phraseType) && !LvtbRoles.CRDPART.equals(partRole))
continue;
// Do not add split ellipsis nodes.
if (LvtbRoles.ELLIPSIS_TOKEN.equals(partRole))
continue;

String partId = phrasePart.getId();
HashSet<String> collectedPartSubjs = resultAccumulator.get(partId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package lv.ailab.lvtb.universalizer.transformator.syntax;

import lv.ailab.lvtb.universalizer.pml.LvtbRoles;
import lv.ailab.lvtb.universalizer.pml.PmlANode;
import lv.ailab.lvtb.universalizer.pml.utils.PmlANodeListUtils;
import lv.ailab.lvtb.universalizer.transformator.Sentence;
import lv.ailab.lvtb.universalizer.transformator.TransformationParams;
import lv.ailab.lvtb.universalizer.transformator.morpho.XPosLogic;
Expand Down Expand Up @@ -139,9 +137,11 @@ else if (aNode.isPureReductionNode())
if (redXPostag.matches("v..([^p].*|p[du].*)") || ! params.UD_STANDARD_NULLNODES)
{
String newIdStub = newBasicRoot.getId();
List<PmlANode> tokenNodes = aNode.getChildren(LvtbRoles.ELLIPSIS_TOKEN);
if (tokenNodes != null && !tokenNodes.isEmpty())
newIdStub = PmlANodeListUtils.getFirstByDescOrd(tokenNodes).getId();
//List<PmlANode> tokenNodes = aNode.getChildren(LvtbRoles.ELLIPSIS_TOKEN);
//if (tokenNodes != null && !tokenNodes.isEmpty())
// newIdStub = PmlANodeListUtils.getFirstByDescOrd(tokenNodes).getId();
PmlANode tokenNode = s.pmlTree.getDescendant(aNode.getId() + Sentence.ID_POSTFIX);
if (tokenNode != null) newIdStub = tokenNode.getId();
s.createNewEnhEllipsisNode(aNode, newIdStub, params.ADD_NODE_IDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ else if (nominal && ultimateAux)
return Tuple.of(UDv2Relations.XCOMP, null);
}

if (lvtbRole.equals(LvtbRoles.ELLIPSIS_TOKEN))
{
String tag = aNode.getAnyTag();
if (tag.matches("z.*")) return Tuple.of(UDv2Relations.PUNCT, null);
}

StandardLogger.l.doInsentenceWarning(String.format(
"\"%s\" (%s) in \"%s\" has no UD label.",
lvtbRole, nodeId, phraseType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,36 +675,43 @@ protected PmlANode noModXPredToUD(PmlANode xNode)
{
// Get basElems and warn if there is none.
List<PmlANode> basElems = xNode.getChildren(LvtbRoles.BASELEM);
if (basElems != null && basElems.size() > 1)
throw new IllegalArgumentException(String.format(
"\"%s\" in sentence \"%s\" has multiple \"basElem\"",
xNode.getPhraseType(), s.id));
PmlANode basElem = PmlANodeListUtils.getLastByDeepOrd(basElems);
if (basElem == null)
throw new IllegalArgumentException(String.format(
"\"%s\" in sentence \"%s\" has no \"basElem\"",
xNode.getPhraseType(), s.id));
PmlANode newRoot = basElem;

List<PmlANode> auxes = xNode.getChildren(LvtbRoles.AUXVERB);
PmlANode lastAux = PmlANodeListUtils.getLastByDeepOrd(auxes);
if (lastAux == null)
/*if (lastAux == null)
throw new IllegalArgumentException(String.format(
"\"%s\" in sentence \"%s\" has neither \"auxVerb\" nor \"mod\"",
xNode.getPhraseType(), s.id));
if (auxes.size() > 1) for (int i = 0; i < auxes.size(); i++)
xNode.getPhraseType(), s.id));*/
if (lastAux != null)
{
String auxLemma = lastAux.getM().getLemma();
if (auxes.size() > 1) for (int i = 0; i < auxes.size(); i++)
{
String auxLemma = lastAux.getM().getLemma();
String auxRedLemma = lastAux.getReductionLemma();
if (!MorphoTransformator.isTrueAux(auxLemma) &&
!MorphoTransformator.isTrueAux(auxRedLemma))
StandardLogger.l.doInsentenceWarning(String.format(
"xPred \"%s\" has multiple auxVerb one of which has lemma \"%s\".",
xNode.getParent().getId(), auxLemma));
}

PmlMNode lastAuxM = lastAux.getM();
String auxLemma = lastAuxM == null ? null : lastAuxM.getLemma();
String auxRedLemma = lastAux.getReductionLemma();
if (!MorphoTransformator.isTrueAux(auxLemma) &&
!MorphoTransformator.isTrueAux(auxRedLemma))
StandardLogger.l.doInsentenceWarning(String.format(
"xPred \"%s\" has multiple auxVerb one of which has lemma \"%s\".",
xNode.getParent().getId(), auxLemma));
boolean ultimateAux = MorphoTransformator.isTrueAux(auxLemma)
|| MorphoTransformator.isTrueAux(auxRedLemma);
if (!ultimateAux) newRoot = lastAux;
}

PmlMNode lastAuxM = lastAux.getM();
String auxLemma = lastAuxM == null ? null : lastAuxM.getLemma();
String auxRedLemma = lastAux.getReductionLemma();
boolean ultimateAux = MorphoTransformator.isTrueAux(auxLemma)
|| MorphoTransformator.isTrueAux(auxRedLemma);

PmlANode newRoot = basElem;
if (!ultimateAux) newRoot = lastAux;
List<PmlANode> children = xNode.getChildren();
s.relinkAllConstituents(newRoot, children, xNode,
params.PROPAGATE_CONJUNCTS, params.NO_EDEP_DUPLICATES);
Expand Down

0 comments on commit 7128e3f

Please sign in to comment.