private static IEnumerable <TagMatch> GetTagMatches(IList <TagMatch> tagMatchesPerChar, IEnumerable regexMatches, InlineType inlineType, MatchRule matchRule) { foreach (Match regexMatch in regexMatches) { var newTagMatch = new TagMatch(inlineType, regexMatch, matchRule); var currentTagMatch = tagMatchesPerChar[newTagMatch.Start]; if (currentTagMatch != null && currentTagMatch.End == newTagMatch.End) { continue; } var indexBeforeNewTagMatch = newTagMatch.Start - 1; if (newTagMatch.Start != 0 && tagMatchesPerChar[indexBeforeNewTagMatch] != null && tagMatchesPerChar[indexBeforeNewTagMatch].End >= newTagMatch.Start) { continue; } var indexAfterNewTagMatch = newTagMatch.Start + newTagMatch.Length; if (indexAfterNewTagMatch != tagMatchesPerChar.Count && tagMatchesPerChar[indexAfterNewTagMatch] != null && tagMatchesPerChar[indexAfterNewTagMatch].Start <= newTagMatch.End) { continue; } yield return(newTagMatch); } }
private TagMatch[] GetTagMatchesPerChar(string value) { var tagMatchesPerChar = new TagMatch[value.Length]; foreach (var matchRule in _matchRules) { var startTagRegexMatches = GetRegexMatches(value, matchRule.StartTagRegexValue, matchRule.IgnoreCase); if (matchRule.TagType == MatchRule.TagTypeOption.Placeholder) { AddTagMatches(tagMatchesPerChar, startTagRegexMatches, InlineType.Placeholder, matchRule); continue; } var endTagRegexMatches = GetRegexMatches(value, matchRule.EndTagRegexValue, matchRule.IgnoreCase); var startTagInlineType = InlineType.StartTag; var endTagInlineType = InlineType.EndTag; var startTagMatches = GetTagMatches(tagMatchesPerChar, startTagRegexMatches, startTagInlineType, matchRule); var endTagMatches = GetTagMatches(tagMatchesPerChar, endTagRegexMatches, endTagInlineType, matchRule); if (!IsInvalidOrder(startTagMatches, endTagMatches)) { startTagInlineType = InlineType.Placeholder; endTagInlineType = InlineType.Placeholder; } AddTagMatches(tagMatchesPerChar, startTagRegexMatches, startTagInlineType, matchRule); AddTagMatches(tagMatchesPerChar, endTagRegexMatches, endTagInlineType, matchRule); } return(tagMatchesPerChar); }
/// <summary> /// Find game objects that match the given tags /// </summary> /// <param name="tag1">The tag name</param> /// <param name="tagMatchType">Match tags by "Or" (any of the given tags can be selected on the object) or by "And" (all of the given tags must be selected on the object)</param> /// <returns>A list of matching game objects</returns> public static List <GameObject> FindGameObjectsWithTags(Tags tag1, TagMatch tagMatchType = TagMatch.Or) { List <string> temp = new List <string>() { tag1.ToString() }; return(FindGameObjectsWithTags(temp, tagMatchType)); }
private IEnumerable<TagMatch> FindMatchesWithFeatureMass(MatchedTag matchedTag) { if (matchedTag.NTermFlankingMass == null || matchedTag.CTermFlankingMass == null) yield break; var featureMass = (double) matchedTag.NTermFlankingMass + matchedTag.Mass + (double)matchedTag.CTermFlankingMass + Composition.H2O.Mass; var shiftMass = matchedTag.Mass + (double)matchedTag.NTermFlankingMass; var backwardGraph = new ShiftedSequenceGraph(_aaSet, shiftMass, false, matchedTag.StartIndex, featureMass - MinSumModificationMasses); foreach (var backwardMatch in GetBackwardMatches(matchedTag, backwardGraph, featureMass)) { // Make a forward graph var nTermShiftMass = backwardMatch.Mass + matchedTag.Mass; var forwardGraph = new ShiftedSequenceGraph(_aaSet, nTermShiftMass, true, _proteinSequence.Length - matchedTag.EndIndex, featureMass - MinSumModificationMasses); foreach ( var forwardMatch in GetForwardMatches(matchedTag, forwardGraph, featureMass)) { var mass = forwardMatch.Mass + matchedTag.Mass + backwardMatch.Mass; if (mass > _maxSequenceMass) continue; var offset = matchedTag.EndIndex - backwardMatch.Index - 1; var modStr = string.Join(",", backwardMatch.Modifications.Concat(forwardMatch.Modifications.Select(m => m.GetModificationInstanceWithOffset(offset)))); var modList = new List<Modification>(); foreach (var mod in backwardMatch.Modifications) modList.Add(mod.Modification); foreach (var mod in forwardMatch.Modifications) modList.Add(mod.Modification); var tagMatch = new TagMatch( backwardMatch.Index, forwardMatch.Index, matchedTag.Length, backwardMatch.Charge, backwardMatch.Score, forwardMatch.Score, mass, new ModificationCombination(modList), modStr); yield return tagMatch; } } }
/// <summary> /// Find game objects that match the given tags /// </summary> /// <param name="tag1">The tag name</param> /// <param name="tag2">The tag name</param> /// <param name="tag3">The tag name</param> /// <param name="tagMatchType">Match tags by "Or" (any of the given tags can be selected on the object) or by "And" (all of the given tags must be selected on the object)</param> /// <returns>A list of matching game objects</returns> public static List <GameObject> FindGameObjectsWithTags(string tag1, string tag2, string tag3, TagMatch tagMatchType = TagMatch.Or) { List <string> temp = new List <string>() { tag1, tag2, tag3 }; return(FindGameObjectsWithTags(temp, tagMatchType)); }
/// <summary> /// Find game objects that match the given tags /// </summary> /// <param name="tags">A string list of tags to match</param> /// <param name="tagMatchType">Match tags by "Or" (any of the given tags can be selected on the object) or by "And" (all of the given tags must be selected on the object)</param> /// <returns>A list of matching game objects</returns> public static List <GameObject> FindGameObjectsWithTags(List <string> tags, TagMatch tagMatchType) { TagFrenzyList[] tagged = GameObject.FindObjectsOfType <TagFrenzyList>(); List <GameObject> matches = new List <GameObject>(); //Look through all objects with a tagger attached for (int i = 0; i < tagged.Length; i++) { TagFrenzyList obj = tagged[i]; if (tagMatchType == TagMatch.Or) { //Look through all the entered tags, and see any of them match for (int j = 0; j < tags.Count; j++) { if (obj.SelectedEditorTags.Where(et => et.Tag.ToLower().Trim() == tags[j].ToLower().Trim()).Any()) { //If so, return it matches.Add(obj.gameObject); break; } } } else if (tagMatchType == TagMatch.And) { //Look through all the entered tags, and see if all of them match bool addMatch = true; for (int j = 0; j < tags.Count; j++) { if (!obj.SelectedEditorTags.Where(et => et.Tag.ToLower().Trim() == tags[j].ToLower().Trim()).Any()) { addMatch = false; } } if (addMatch) { matches.Add(obj.gameObject); } } else if (tagMatchType == TagMatch.Not) { bool addMatch = true; for (int j = 0; j < tags.Count; j++) { if (obj.SelectedEditorTags.Where(et => et.Tag.ToLower().Trim() == tags[j].ToLower().Trim()).Any()) { addMatch = false; } } if (addMatch) { matches.Add(obj.gameObject); } } else if (tagMatchType == TagMatch.Exact) { bool addMatch = true; int matchCount = 0; for (int j = 0; j < tags.Count; j++) { //Make sure all the tags match if (!obj.SelectedEditorTags.Where(et => et.Tag.ToLower().Trim() == tags[j].ToLower().Trim()).Any()) { addMatch = false; } else { matchCount += 1; } } //And make sure there are only matching tags in the result if (matchCount != obj.SelectedEditorTags.Count()) { addMatch = false; } if (addMatch) { matches.Add(obj.gameObject); } } } return(matches); }
private static TagMatch GetTagMatchRight(IList<string> tagList, IList<IList<string>> matchingTagList, TagMatchMode mode) { int loopCount = 1; // default to one - gets overridden if continueOnMiss == true TagMatch match = new TagMatch(); match.Tag = null; match.Length = 0; match.Index = -1; bool requireFirstTagMatch = (TagMatchMode.REQUIRE_FIRST_MATCH & mode) == TagMatchMode.REQUIRE_FIRST_MATCH; // first only is the default. Override it to make sure we check all input strings until we get a match or checked them all. if (!requireFirstTagMatch) { loopCount = tagList.Count; } // loop through input tags - <i> will be current tag String (or current partial tag string) for (int i = 0; i < loopCount; i++) { int iInverse = tagList.Count - 1 - i; // loop through all the matching tags for (int j = 0; j < matchingTagList.Count; j++) { // check if tags can "fit" current matchingTag (if the current matchingTag is bigger than input tagList, then obviously it cannot match) if ((tagList.Count - i) >= matchingTagList[j].Count) { // remove the <i>th last elements in tagList (they've already been dismissed) List<string> uncheckedTagsList = ((List<string>)tagList).GetRange(0, iInverse + 1); bool tagMatch = isTagMatch(uncheckedTagsList, matchingTagList[j], mode | TagMatchMode.RIGHT_TO_LEFT); if (tagMatch == true) { match.Index = iInverse; match.Length = matchingTagList[j].Count; match.MatchIndex = j; match.Tag = new Tag(uncheckedTagsList.GetRange(match.Index, match.Length)); return match; } } } } return match; }
public override string ToString() { return(TagMatch.ToString()); }
private static TagMatch GetTagMatch(IList<string> tagList, IList<IList<string>> matchingTagList, bool continueOnMiss) { int loopCount; TagMatch match = new TagMatch(); match.Tag = null; match.Length = 0; match.Index = -1; if (!continueOnMiss) { loopCount = 1; } else { loopCount = tagList.Count; } // loop through input tags - <i> will be current tag String (or current partial tag string) for (int i = 0; i < loopCount; i++) { // loop through all the matching tags for (int j = 0; j < matchingTagList.Count; j++) { // check if tags can "fit" current wellknownTag (if the current matchingTag is bigger than input tagList, then obviously it cannot match) if ((tagList.Count - i) >= matchingTagList[j].Count) { // loop through all tags (atomic string part of composite tag (for instance "READ" in tag: "READ.NFO")) for (int k = 0; k < matchingTagList[j].Count; k++) { if (tagList[i + k].ToUpper() != matchingTagList[j][k].ToUpper()) { // didnt match - check next one. break; } else if (k == matchingTagList[j].Count - 1) { // matched full known tag. (we're on the last loop, and we never broke out of the loop - all previous tags we looped through were matches.) // create Tag object from strings match.Tag = new Tag(((List<string>)tagList).GetRange(i, k + 1)); match.Index = i; match.Length = k + 1; return match; } } } } } return match; }
public TagSequenceMatch(string sequence, string proteinName, TagMatch tagMatch, char pre, char post) { Sequence = sequence; ProteinName = proteinName; TagMatch = tagMatch; Pre = pre; Post = post; }
/// <summary> /// Find game objects that match the given tags /// </summary> /// <param name="tags">A string list of tags to match</param> /// <param name="tagMatchType">Match tags by "Or" (any of the given tags can be selected on the object) or by "And" (all of the given tags must be selected on the object)</param> /// <returns>A list of matching game objects</returns> public static List<GameObject> FindGameObjectsWithTags(List<string> tags, TagMatch tagMatchType) { TagFrenzyList[] tagged = GameObject.FindObjectsOfType<TagFrenzyList>(); List<GameObject> matches = new List<GameObject>(); //Look through all objects with a tagger attached for (int i = 0; i < tagged.Length; i++) { TagFrenzyList obj = tagged[i]; if (tagMatchType == TagMatch.Or) { //Look through all the entered tags, and see any of them match for (int j = 0; j < tags.Count; j++) { if (obj.SelectedEditorTags.Where(et=>et.Tag.ToLower().Trim() == tags[j].ToLower().Trim()).Any()) { //If so, return it matches.Add(obj.gameObject); break; } } } else if (tagMatchType == TagMatch.And) { //Look through all the entered tags, and see if all of them match bool addMatch = true; for (int j = 0; j < tags.Count; j++) { if (!obj.SelectedEditorTags.Where(et=>et.Tag.ToLower().Trim() == tags[j].ToLower().Trim()).Any()) { addMatch = false; } } if (addMatch) { matches.Add(obj.gameObject); } } else if (tagMatchType == TagMatch.Not) { bool addMatch = true; for (int j = 0; j < tags.Count; j++) { if (obj.SelectedEditorTags.Where(et => et.Tag.ToLower().Trim() == tags[j].ToLower().Trim()).Any()) { addMatch = false; } } if (addMatch) { matches.Add(obj.gameObject); } } else if (tagMatchType == TagMatch.Exact) { bool addMatch = true; int matchCount = 0; for (int j = 0; j < tags.Count; j++) { //Make sure all the tags match if (!obj.SelectedEditorTags.Where(et => et.Tag.ToLower().Trim() == tags[j].ToLower().Trim()).Any()) { addMatch = false; } else { matchCount += 1; } } //And make sure there are only matching tags in the result if (matchCount != obj.SelectedEditorTags.Count()) { addMatch = false; } if (addMatch) { matches.Add(obj.gameObject); } } } return matches; }
/// <summary> /// Find game objects that match the given tags /// </summary> /// <param name="tag1">The tag name</param> /// <param name="tag2">The tag name</param> /// <param name="tag3">The tag name</param> /// <param name="tagMatchType">Match tags by "Or" (any of the given tags can be selected on the object) or by "And" (all of the given tags must be selected on the object)</param> /// <returns>A list of matching game objects</returns> public static List<GameObject> FindGameObjectsWithTags(Tags tag1, Tags tag2, Tags tag3, TagMatch tagMatchType = TagMatch.Or) { List<string> temp = new List<string>() { tag1.ToString(), tag2.ToString(), tag3.ToString() }; return FindGameObjectsWithTags(temp, tagMatchType); }
/// <summary> /// Find game objects that match the given tags /// </summary> /// <param name="tag1">The tag name</param> /// <param name="tag2">The tag name</param> /// <param name="tag3">The tag name</param> /// <param name="tagMatchType">Match tags by "Or" (any of the given tags can be selected on the object) or by "And" (all of the given tags must be selected on the object)</param> /// <returns>A list of matching game objects</returns> public static List<GameObject> FindGameObjectsWithTags(string tag1, string tag2, string tag3, TagMatch tagMatchType = TagMatch.Or) { List<string> temp = new List<string>() { tag1, tag2, tag3 }; return FindGameObjectsWithTags(temp, tagMatchType); }