// Seqs := ",", Seq, Seqs // | "" private void Seqs(ref IPhrase aPhr) { if (lex != null) { if (lex.Type == LexemType.Operation) { if (lex.Text == "," || lex.Text == ";") { bool lIsComma = lex.Text == ","; lex = lex.Next(); Seqence lSeq = aPhr as Seqence; if (lSeq == null) { lSeq = new Seqence(mGrammar, aPhr); lSeq.InsertSpace = lIsComma; aPhr = lSeq; } IPhrase lSeqPhr = Seq(); lSeq.Add(lSeqPhr); AsAlias(ref lSeqPhr); Seqs(ref aPhr); } } //else //{ // throw new GrammarSynaxException(string.Format("'{0}' not expected here (,) operation expected", lex.Text)); //} } }
public static bool IsMatch(this LanguagePhrase knownPhrase, IPhrase phrase) { return(knownPhrase.first == phrase.First && knownPhrase.second == phrase.Second && (string.IsNullOrWhiteSpace(knownPhrase.firstMust) || knownPhrase.firstMust.Equals(phrase.FirstValue, StringComparison.OrdinalIgnoreCase))); }
protected override IDerivation ExpandRnd(DerivationContext aContext) { DictionaryDerivation lList = new DictionaryDerivation(InsertSpace, aContext); int lExprCnt = 1; for (int i = 0; i < mPhrases.Count; i++) { IPhrase lPhr = mPhrases[i]; IDerivation lRes = lPhr.Expand(aContext); string lKeyName; Symbol lCurrentSymbol = lPhr as Symbol; if (lCurrentSymbol != null) { lCurrentSymbol.OccurenceInSeq = i; lKeyName = lCurrentSymbol.Text; //взять протокол вывода этого правила //TODO: aContext.RuleSeqProtocol.Add(lCurrentSymbol.Text, lRes); //добавить в его протокол вывода последовательности имя lCurrentSymbol.Text и результат lRes } else { lKeyName = string.Format("Expr{0}", lExprCnt++); } lList.Add(lKeyName, lRes, aContext); } return(lList); }
protected override DerivationContext NewContext(IPhrase aPhrase, DerivationContext aContext) { CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext); newContext.Parent = aPhrase; return(newContext); }
//protected Grammar mGrammar; public Rule(Grammar aGrammar, Lexema aLex) { if (aLex == null || aLex.Type != LexemType.NotTerminal) { throw new GrammarSyntaxException("Rule Name expected"); } Name = aLex.Text; aLex = aLex.Next(); if (aLex != null && aLex.Type == LexemType.Terminal) { mSeparator = aLex.Text; aLex = aLex.Next(); } if (aLex == null || aLex.Type != LexemType.IsSign) { throw new GrammarSyntaxException(":= expected"); } aLex = aLex.Next(); PhraseParser lParser = new PhraseParser(aGrammar, aLex); RightSide = lParser.ParseRule(); }
private void Quant(ref IPhrase aPhr) { // look for quantifier here if (lex != null && (lex.Text == "{" || lex.Text == "*" || lex.Text == "+" || lex.Text == "?")) { ExprInt lMin = null, lMax = null; //{1..5} if (lex.Text == "{") { lex = lex.Next(); lMin = ParseIntValue(); if (lex.Text == ".") { lex = lex.Next(); ExpectSign("."); if (lex.Text == "*") { lMax = new ExprInt(Int32.MaxValue); } else { lMax = ParseIntValue(); } } else { lMax = lMin; } ExpectSign("}"); } else if (lex.Text == "*") { lMin = new ExprInt(0); lMax = new ExprInt(int.MaxValue); lex = lex.Next(); } else if (lex.Text == "+") { lMin = new ExprInt(1); lMax = new ExprInt(int.MaxValue); lex = lex.Next(); } else if (lex.Text == "?") { lMin = new ExprInt(0); lMax = new ExprInt(1); lex = lex.Next(); } else { throw new GrammarSyntaxException("Недолжно быть. Неподдерживаемый знак после нетерминала " + lex.Text); } QuantifiedPhrase lQuant = new QuantifiedPhrase(mGrammar, aPhr, lMin, lMax); aPhr = lQuant; } }
public QuantifiedPhrase(Grammar aGrammar, IPhrase aPhr, ExprInt aMin, ExprInt aMax) : base(aGrammar) { Phrase = aPhr; Min = aMin; Max = aMax; IsConfigurable = false; }
private static IPhrase TrimByKeyword(this IPhrase @this) { if (@this.Comment.StartsWith(@this.Right)) { @this.Comment = @this.Comment.Remove(0, @this.Right.Length); } return(@this); }
private static IPhrase NullToStringEmpty(this IPhrase @this) { if (@this.Comment == null) { @this.Comment = string.Empty; } return(@this); }
public string GenerateString(IPhrase phrase) { StringWriter writer = new StringWriter(); Generate(phrase, writer); writer.Close(); return(writer.ToString()); }
private IPhrase Alt() { IPhrase lPhr = Seq(); AsAlias(ref lPhr); Seqs(ref lPhr); return(lPhr); }
public static UIElement CreateControl(IPhrase element, List <string> aOuterSymbols) { if (element is Seqence) { MainWindow.AllSequenses++; return(new SeqenceControl(element as Seqence, aOuterSymbols)); } else if (element is AlternativeSet) { MainWindow.AllAlternativeSets++; return(new AlternativeControl(element as AlternativeSet, aOuterSymbols)); } else if (element is QuantifiedPhrase) { return(new QuantifierControl(element as QuantifiedPhrase, aOuterSymbols)); } else if (element is NonTerminal) { NonTerminal s = element as NonTerminal; MainWindow.AllNonTerminals++; return(new NonTerminalControl(s, aOuterSymbols)); } else if (element is Terminal) { Terminal s = element as Terminal; Label l = new Label(); l.Content = s.Text; //Run r = new Run(s.Text); l.Foreground = Brushes.Red; return(l); } Label unk = new Label(); if (element is AccessSeq) { AccessSeq acc = element as AccessSeq; unk.Content = "#" + acc.ObjectName + "." + acc.mFieldName; } else if (element is TransCallPhrase) { TransCallPhrase trans = element as TransCallPhrase; unk.Content = "call " + trans.BindedMethod.Name; } else if (element is AccessArray) { AccessArray ar = element as AccessArray; unk.Content = ar.ObjectName + "[" + ar.IndexExpr.ToString() + "]"; } else { unk.Content = "unknown:" + element.ToString(); } return(unk); }
private static IEnumerable <IWordItem> GetImportantInternal(this IEnumerable <IWordItem> words) { IPhrase parent = null; foreach (var wordItem in words) { if (wordItem.CanNotBeAttribute() && wordItem.CanNotBeFeature() && !wordItem.IsFeature && !wordItem.IsSentiment && wordItem.Relationship.Sentiment == null && !wordItem.IsInvertor) { continue; } if (!(wordItem.Parent is IPhrase currentParent) || currentParent.AllWords.Count() <= 1) { yield return(wordItem); continue; } if (parent == currentParent) { continue; } parent = currentParent; if (parent.IsFeature || parent.IsSentiment) { yield return(parent); } else { foreach (var child in parent.AllWords) { if (child.IsFeature || child.IsSentiment) { yield return(child); continue; } if (child.IsStopWord && !WordTypeResolver.Instance.IsSpecialEndSymbol(child.Text)) { continue; } yield return(child); } } } }
public override IDerivation Visit(IPhrase aPhr, DerivationContext aContext) { CyclesDetectContext context = aContext as CyclesDetectContext; aPhr.Parent = context.Parent; CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext); newContext.Parent = aPhr; return(base.Visit(aPhr, newContext)); }
public SpanQuery Parse(string field, TokenStream ts, IndexReader reader) { IPhrase phrase = Parse(ts); if (phrase == null) { return(null); } return(phrase.BuildQuery(field, reader, true, true)); }
public IPhrase ParseRule() { IPhrase lPhr = ParsePhrase(); if (lex != null) { throw new GrammarSyntaxException(string.Format("rule parse error! {0} found", lex.Text)); } return(lPhr); }
private static void PrettyPrint(string indent, IPhrase phrase, int lno, int ofs, int len, string title, object val) { Console.WriteLine(quickNDirtyIndent + String.Format("{0}\t\"{1}\" (line {2}) (ofs: {3}) (len: {4})", title, (val ?? String.Empty).ToString().Replace("\r\n", String.Empty), lno, ofs, len)); quickNDirtyIndent += " "; foreach (IPhrase item in phrase.Content) { PrettyPrint(indent, item, item.Line, item.Offset, item.Length, item.Ident, item.Literal); } quickNDirtyIndent = quickNDirtyIndent.Substring(0, quickNDirtyIndent.Length - 2); }
public IParsedReview Create() { if (review != null) { return(review); } review = new ParsedReview(nrcDictionary, document, manager.Context); foreach (var sentence in document.Sentences) { CreateSentence(sentence); IPhrase phrase = null; string phraseWord = null; for (var i = 0; i < sentence.Words.Count; i++) { var documentWord = sentence.Words[i]; if (documentWord.Phrase != null) { if (phraseWord != documentWord.Phrase) { phraseWord = documentWord.Phrase; phrase = documentWord.UnderlyingWord as IPhrase ?? wordsFactory.CreatePhrase(phraseWord); } } else { phrase = null; phraseWord = null; } // !! we need to create new - because if we use underlying // we can lose if words is changed to aspect IWordItem word = wordsFactory.CreateWord(documentWord.Text, documentWord.POS); word.NormalizedEntity = documentWord.NormalizedEntity; word.Entity = documentWord.EntityType; word.CustomEntity = documentWord.CustomEntity; word.WordIndex = i; AddWord(word, i == sentence.Words.Count - 1); phrase?.Add(word); } } foreach (var sentence in review.Sentences) { foreach (var phrase in sentence.Occurrences.GetPhrases().Where(item => item.AllWords.Count() > 1)) { phrase.IsSentiment = manager.IsSentiment(phrase); phrase.IsFeature = manager.IsFeature(phrase); phrase.IsTopAttribute = manager.IsAttribute(phrase); } } return(review); }
private IPhrase ParsePhrase() { if (lex == null) { throw new GrammarSyntaxException("Phrase expected"); } IPhrase lAlt = Alt(); Alts(ref lAlt); return(lAlt); }
public virtual void Add(IPhrase aPhr2) { if (aPhr2 is PhraseList && GetType() == aPhr2.GetType()) { PhraseList lPhrList = aPhr2 as PhraseList; mPhrases.AddRange((List <IPhrase>)lPhrList); } else { mPhrases.Add(aPhr2); } }
public bool IsValidPhrase(IPhrase phrase) { foreach (var phraseSpec in _langSpec.phrases) { if (phraseSpec.IsMatch(phrase)) { return(true); } } return(false); }
private void AsAlias(ref IPhrase aPhr) { if (null != lex) { if (lex.Type == LexemType.NotTerminal && lex.Text.ToLower() == "as") { lex = lex.Next(); CheckType(LexemType.NotTerminal); aPhr.Alias = lex.Text; lex = lex.Next(); } } }
private void DParseErrorPhrase(IStatement phrase, StringWriter writer) { var phrases = (phrase as ParseErrorPhrase).Phrases; for (int i = 0; i < phrases.Length; i++) { IPhrase innerPhrase = phrases[i]; if (innerPhrase is IPhraseContainer) { Generate(innerPhrase, writer); } } }
public IEnumerable <IPhrase> GetPhrases(IWordItem word) { if (word == null) { throw new ArgumentNullException(nameof(word)); } log.LogDebug("GetPhrases {0}", word); IWordItem[] currentWords = word.Relationship.Part.Occurrences .Where(item => !item.CanNotBeFeature() && !item.IsSentiment).ToArray(); if (currentWords.Length <= 1) { yield break; } var all = string.Join(" ", currentWords.Select(item => item.Text).ToArray()); var wordIndex = Array.IndexOf(currentWords, word); if (wordIndex < 0) { log.LogDebug("{0} is not found in important list in <{1}>", word, all); yield break; } var nGramBlocks = new List <NGramBlock>(); var wordsTable = new Dictionary <WordEx, IWordItem>(); var words = new WordEx[currentWords.Length]; foreach (IWordItem item in currentWords) { WordEx wordEx = WordExFactory.Construct(item); words[wordsTable.Count] = wordEx; wordsTable[wordEx] = item; } nGramBlocks.AddRange(words.GetNearNGram(wordIndex, 3)); nGramBlocks.AddRange(words.GetNearNGram(wordIndex, 2)); foreach (NGramBlock nGramBlock in nGramBlocks) { IPhrase phrase = handler.CreatePhrase("NP"); foreach (WordEx occurence in nGramBlock.WordOccurrences) { phrase.Add(wordsTable[occurence]); } yield return(phrase); } }
public override IDerivation Visit(AlternativeSet aAlternativeSet, DerivationContext aContext) { for (int i = 0; i < aAlternativeSet.Count; i++) { IPhrase phr = aAlternativeSet.Phrases[i]; if (OmmitTerminals && phr is Terminal) { continue; } tEdge edge = addEdge(aContext, phr, aAlternativeSet.Parent); edge.CustomAttributes = phr.IsCyclic ? GrammarGraphEdgeAttrs.IsCyclic : GrammarGraphEdgeAttrs.None; phr.Accept(NewContext(aAlternativeSet, aContext)); } return(null); }
/// <summary>フレーズからプログラムを生成します</summary> private void Generate(IPhrase phrase, StringWriter writer) { if (phrase == null) { return; } StatementDelegate act; if (actions.TryGetValue(phrase.PhraseType, out act)) { act(phrase, writer); } else if (phrase is IPhraseContainer) { Generate((phrase as IPhraseContainer).Phrases, writer); } }
public override IDerivation Visit(Seqence aSeqence, DerivationContext aContext) { for (int i = 0; i < aSeqence.Count; i++) { IPhrase phr = aSeqence.Phrases[i]; if (OmmitTerminals && phr is Terminal) { continue; } tEdge edge = addEdge(aContext, phr, aSeqence.Parent); edge.CustomAttributes = GrammarGraphEdgeAttrs.IsSequence | (phr.IsCyclic ? GrammarGraphEdgeAttrs.IsCyclic : GrammarGraphEdgeAttrs.None); phr.Accept(NewContext(aSeqence, aContext)); } return(null); }
private static IPhrase LineToMultiline(this IPhrase @this) { var matches = Regex.Split(@this.Comment, NumberDotPattern); if (matches.Any() && matches.Length > 1) { var newMatches = new List <string>(); for (var i = 0; i < matches.Length; i++) { var match = matches[i]; if (match.StartsWithNumberDot()) { if (i + 1 <= matches.Length) { matches[i + 1] = matches[i] + matches[i + 1]; newMatches.Add(matches[i + 1]); i++; } } else { newMatches.Add(match); } } @this.Comment = string.Empty; if ([email protected]()) { @this.Comment = newMatches.First().ToH5(); @this.Comment += string.Join("", newMatches.Skip(1).Select(x => x.ProcessString())); } else { @this.Comment = string.Join("", newMatches.Select(x => x.ProcessString())); } } else { @this.Comment = @this.Comment.ToH5(); } return(@this); }
public static NonTerminal Create(Grammar aGrammar, IPhrase aParent, string aText) { //for terminal we don't return existing object, because it may be modified (terminal) bool lAllreadyExists = aGrammar.AllNonTerminals.ContainsKey(aText); NonTerminalCommon common; if (lAllreadyExists) { common = aGrammar.AllNonTerminals[aText]; } else { common = new NonTerminalCommon(aGrammar, aText); aGrammar.AllNonTerminals.Add(aText, common); } NonTerminal lSym = new NonTerminal(common, aParent); lSym.OccurenceId = common.AllOccurences.Count; common.AllOccurences.Add(lSym); return(lSym); }
private PlaceHolderPhrase PlaceHolderAssign(string aName) { if (lex.Type == LexemType.Sign) { if (lex.Text == "=") { lex = lex.Next(); IPhrase lPhr = Seq(); AsAlias(ref lPhr); return(new PlaceHolderAssignPhrase(mGrammar, aName, lPhr, false)); } else if (lex.Text == "+") { lex = lex.Next(); IPhrase lPhr = Seq(); AsAlias(ref lPhr); return(new PlaceHolderAssignPhrase(mGrammar, aName, lPhr, true)); } } return(new PlaceHolderPhrase(mGrammar, aName)); }
public static MD5 MD5(IPhrase phrase, bool binary = false) { return new MD5(phrase, binary); }
public static Second Second(IPhrase phrase) { return new Second(phrase); }
public static StandardDeviationOfSample StandardDeviationOfSample(IPhrase phrase) { return new StandardDeviationOfSample(phrase); }
public static Year Year(IPhrase phrase) { return new Year(phrase); }
public static DateTimeAdd DateTimeAdd(IPhrase phrase, DateTimeUnit unit, string addColumnName) { return new DateTimeAdd(phrase, unit, addColumnName); }
public static DateTimeAdd DateTimeAdd(IPhrase phrase, DateTimeUnit unit, Int64 interval) { return new DateTimeAdd(phrase, unit, interval); }
public static SHA1 SHA1(IPhrase phrase, bool binary = false) { return new SHA1(phrase, binary); }
public static StandardVarianceOfSample StandardVarianceOfSample(IPhrase phrase) { return new StandardVarianceOfSample(phrase); }
public static JsonExtract JsonExtract(IPhrase phrase, string path = "$") { return new JsonExtract(phrase, path); }
public static Avg Avg(IPhrase phrase) { return new Avg(phrase); }
public static RandWeight RandWeight(IPhrase phrase) { return new RandWeight(phrase); }
public static CountDistinct CountDistinct(IPhrase phrase) { return new CountDistinct(phrase); }
public static Round Round(IPhrase phrase, int decimalPlaces = 0) { return new Round(phrase, decimalPlaces); }
public static Min Min(IPhrase phrase) { return new Min(phrase); }
public static Count Count(IPhrase phrase, bool distinct = false) { return new Count(phrase, distinct); }
public static Lower Lower(IPhrase phrase) { return new Lower(phrase); }
public static Max Max(IPhrase phrase) { return new Max(phrase); }
public static Upper Upper(IPhrase phrase) { return new Upper(phrase); }
public static PassThroughAggregate PassThroughAggregate(string aggregateType, IPhrase phrase) { return new PassThroughAggregate(aggregateType, phrase); }
public static Day Day(IPhrase phrase) { return new Day(phrase); }
public static StandardDeviationOfPopulation StandardDeviationOfPopulation(IPhrase phrase) { return new StandardDeviationOfPopulation(phrase); }
public static Hour Hour(IPhrase phrase) { return new Hour(phrase); }
public static StandardVarianceOfPopulation StandardVarianceOfPopulation(IPhrase phrase) { return new StandardVarianceOfPopulation(phrase); }
public static Minute Minute(IPhrase phrase) { return new Minute(phrase); }
public static Sum Sum(IPhrase phrase) { return new Sum(phrase); }
public WhereList OR(IPhrase phrase, WhereComparison comparison, string tableName, string columnName) { var wl = new WhereList(); wl.Add(this); return wl.OR(phrase, comparison, tableName, columnName); }
public RandWeight(IPhrase phrase) : this(phrase, ValueObjectType.Value) { }
public static Length Length(IPhrase phrase) { return new Length(phrase); }
public Query AddWhere(WhereCondition condition, IPhrase phrase) { return Where(new Where(condition, phrase, ValueObjectType.Value, WhereComparision.None, null, ValueObjectType.Literal), false); }
public static Month Month(IPhrase phrase) { return new Month(phrase); }