public static PSMElement GetSignificantAncestorOrSelf(PSMElement element, NodeMarker additionalSignificantNodeMarker) { PSMTreeIterator helper = new PSMTreeIterator(element); while (!((helper.CurrentNode is PSMClass && ((PSMClass)helper.CurrentNode).HasElementLabel) || helper.CurrentNode is PSMContentContainer || (additionalSignificantNodeMarker != null && additionalSignificantNodeMarker(helper.CurrentNode))) && helper.CanGoToParent()) { helper.GoToParent(); } if ((helper.CurrentNode is PSMClass && ((PSMClass)helper.CurrentNode).HasElementLabel) || helper.CurrentNode is PSMContentContainer || (additionalSignificantNodeMarker != null && additionalSignificantNodeMarker(helper.CurrentNode))) { return(helper.CurrentNode); } //else if (!helper.CanGoToParent()) // return helper.CurrentNode; else { return(null); } }
public static IEnumerable <PSMElement> SignificantAncestors(PSMElement element, NodeMarker nodeMarker) { List <PSMElement> result = new List <PSMElement>(); PSMTreeIterator it = new PSMTreeIterator(element); while (it.CanGoToParent()) { it.GoToParent(); PSMElement significantAncestorOrSelf = it.GetSignificantAncestorOrSelf(nodeMarker); result.AddIfNotContained(significantAncestorOrSelf); } return(result); }
public static bool NodeIsUnderRepresentedClass(PSMElement redNode) { PSMTreeIterator it = new PSMTreeIterator(redNode); while (it.CanGoToParent()) { it.GoToParent(); PSMClass psmClass = it.CurrentNode as PSMClass; if (psmClass != null && psmClass.IsReferencedFromStructuralRepresentative()) { return(true); } } return(false); }
public static bool IsInSignificantSubtree(PSMElement node) { PSMTreeIterator it = new PSMTreeIterator(node); PSMElement rootCandidate = null; if (CanBeDocumentRoot(node)) { rootCandidate = node; } while (it.CanGoToParent()) { it.GoToParent(); if (CanBeDocumentRoot(it.CurrentNode)) { rootCandidate = it.CurrentNode; } else if (!(node is PSMClassUnion)) { rootCandidate = null; } } return(rootCandidate != null); }
/// <summary> /// Returns PSM associations between an two nodes (they must be part of a path in the PSM tree). /// (assocations are returned in root to leafes order. /// </summary> /// <param name="ancestor">ancestor node</param> /// <param name="descendant">descendant node</param> public static IEnumerable <PSMAssociation> GetAssociationsBetweenNodes(PSMElement ancestor, PSMElement descendant) { List <PSMAssociation> associations = new List <PSMAssociation>(); PSMTreeIterator it = new PSMTreeIterator(descendant); while (it.CurrentNode != ancestor) { { PSMAssociationChild associationChild = it.CurrentNode as PSMAssociationChild; if (associationChild != null && associationChild.ParentAssociation != null) { associations.Insert(0, associationChild.ParentAssociation); } } if (!it.CanGoToParent()) { throw new ArgumentException("Nodes are not valid ancestor-descendant pair"); } it.GoToParent(); } return(associations); }