Ejemplo n.º 1
0
        public virtual System.String HighlightTerm(System.String originalText, TokenGroup tokenGroup)
        {
            if (tokenGroup.GetTotalScore() == 0)
            {
                return(originalText);
            }
            float score = tokenGroup.GetTotalScore();

            if (score == 0)
            {
                return(originalText);
            }
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<font ");
            if (highlightForeground)
            {
                sb.Append("color=\"");
                sb.Append(GetForegroundColorString(score));
                sb.Append("\" ");
            }
            if (highlightBackground)
            {
                sb.Append("bgcolor=\"");
                sb.Append(GetBackgroundColorString(score));
                sb.Append("\" ");
            }
            sb.Append(">");
            sb.Append(originalText);
            sb.Append("</font>");
            return(sb.ToString());
        }
Ejemplo n.º 2
0
        public override System.String HighlightTerm(System.String originalText, TokenGroup tokenGroup)
        {
            if (tokenGroup.GetTotalScore() == 0)
            {
                return(originalText);
            }
            float score = tokenGroup.GetTotalScore();

            if (score == 0)
            {
                return(originalText);
            }

            // try to size sb correctly
            System.Text.StringBuilder sb = new System.Text.StringBuilder(originalText.Length + EXTRA);

            sb.Append("<span style=\"");
            if (highlightForeground)
            {
                sb.Append("color: ");
                sb.Append(GetForegroundColorString(score));
                sb.Append("; ");
            }
            if (highlightBackground)
            {
                sb.Append("background: ");
                sb.Append(GetBackgroundColorString(score));
                sb.Append("; ");
            }
            sb.Append("\">");
            sb.Append(originalText);
            sb.Append("</span>");
            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public object GetValue(Option modelOption, TokenGroup tokenGroup)
        {
            var value = HasDoubleOption(tokenGroup.Option, modelOption.Definition) ||
                        HasSingleOption(tokenGroup.Option, modelOption.Definition.ShortName);

            return(CheckValue(value, modelOption.Property.PropertyType, modelOption.Definition));
        }
            public string HighlightTerm(string originalText, TokenGroup tokenGroup)
            {
                if (tokenGroup.TotalScore <= 0.0)
                {
                    return(originalText);
                }

                return($"!!!! *{originalText}*");
            }
Ejemplo n.º 5
0
 /* (non-Javadoc)
 * <see cref="Lucene.Net.Highlight.Formatter.highlightTerm(java.lang.String, Lucene.Net.Highlight.TokenGroup)"/>
 */
 public virtual System.String HighlightTerm(System.String originalText, TokenGroup tokenGroup)
 {
     System.Text.StringBuilder returnBuffer;
     if (tokenGroup.TotalScore > 0)
     {
         returnBuffer = new System.Text.StringBuilder();
         returnBuffer.Append(preTag);
         returnBuffer.Append(originalText);
         returnBuffer.Append(postTag);
         return returnBuffer.ToString();
     }
     return originalText;
 }
Ejemplo n.º 6
0
 /* (non-Javadoc)
  * @see Lucene.Net.Highlight.Formatter#highlightTerm(java.lang.String, Lucene.Net.Highlight.TokenGroup)
  */
 public virtual System.String HighlightTerm(System.String originalText, TokenGroup tokenGroup)
 {
     System.Text.StringBuilder returnBuffer;
     if (tokenGroup.GetTotalScore() > 0)
     {
         returnBuffer = new System.Text.StringBuilder();
         returnBuffer.Append(preTag);
         returnBuffer.Append(originalText);
         returnBuffer.Append(postTag);
         return(returnBuffer.ToString());
     }
     return(originalText);
 }
Ejemplo n.º 7
0
        private double CalculateGroup(TokenGroup group, Dictionary <string, double> variables)
        {
            foreach (var token in group.Children)
            {
                if (token.Type == TokenType.Variable)
                {
                    if (!variables.ContainsKey(token.Content))
                    {
                        throw new KeyNotFoundException("Undefined variable " + token.Content);
                    }
                    token.Content = variables[token.Content].ToString();
                    token.Type    = TokenType.Number;
                }
            }

            double value = group.Children[0].NumericValue;

            TokenType operation = TokenType.EOF;

            foreach (var token in group.Children)
            {
                if (token.Type == TokenType.Number)
                {
                    if (operation == TokenType.Multiply)
                    {
                        value *= token.NumericValue;
                    }
                    else if (operation == TokenType.Divide)
                    {
                        value /= token.NumericValue;
                    }
                }
                else
                {
                    operation = token.Type;
                }
            }

            return(value);
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <string> > Post([FromBody] TokenGroup tokenGroup)
        {
            string username;

            try
            {
                RedditAPI reddit = new RedditAPI(System.Environment.GetEnvironmentVariable("VUE_APP_CLIENT_ID"), accessToken: tokenGroup.AccessToken);
                username = reddit.Account.Me.Name;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(Unauthorized(e.Message));
            }

            // No exceptions, token is valid and we have username
            // insert into database and store the primary key
            RedditUser user;

            try
            {
                string hashedUsername = RedditUser.HashUsername(username);
                user = _context.RedditUsers.Single(u => u.Username == hashedUsername);
            }
            catch (InvalidOperationException)
            {
                user = new RedditUser()
                {
                    Username = username
                };
                _context.Add(user);
                _context.SaveChanges();
            }
            // retrieve username using Reddit.NET and variables from .env
            // if successful, store hashed token and hashed username in tables
            // call AuthenticateUser(username, token)
            await AuthenticateUser(user.Id, tokenGroup.RefreshToken);

            return(NoContent());
        }
Ejemplo n.º 9
0
        public IEnumerable <IToken> Group(IEnumerable <Token> tokens)
        {
            var tokenGroup = new TokenGroup();

            foreach (var token in tokens)
            {
                if (token.Type == TokenType.Plus || token.Type == TokenType.Minus)
                {
                    yield return(tokenGroup);

                    tokenGroup = new TokenGroup();
                    yield return(token);
                }
                else
                {
                    tokenGroup.Add(token);
                }
            }
            if (!tokenGroup.Empty)
            {
                yield return(tokenGroup);
            }
        }
        private void MatchAndSetToken(TokenGroup expectedGroup)
        {
            if (this.CurrentToken.Group != expectedGroup)
            {
                throw new MissingTokenException(expectedGroup, this.CurrentToken.Group, ProductionStack.Peek());
            }

            SetNextToken();
        }
Ejemplo n.º 11
0
        private static BuildSeqErrors ParseSequencer(
            SequencerConfigSpecRec Sequencer,
            ScannerRec <SeqKeywordType> Scanner,
            out int ErrorLine)
        {
            TokenRec <SeqKeywordType> Token;
            TokenRec <SeqKeywordType> TokenName;
            TokenRec <SeqKeywordType> TokenGroup;

            ErrorLine = -1;

            while (true)
            {
                Token = Scanner.GetNextToken();
                if (Token.GetTokenType() == TokenTypes.eTokenEndOfInput)
                {
                    break;
                }
                if ((Token.GetTokenType() != TokenTypes.eTokenKeyword) ||
                    (Token.GetTokenKeywordTag() != SeqKeywordType.eSeqKeywordTrack))
                {
                    ErrorLine = Scanner.GetCurrentLineNumber();
                    return(BuildSeqErrors.eBuildSeqExpectedTrack);
                }

                /* parse the track */

                /* "name" */
                TokenName = Scanner.GetNextToken();
                if (TokenName.GetTokenType() != TokenTypes.eTokenString)
                {
                    ErrorLine = Scanner.GetCurrentLineNumber();
                    return(BuildSeqErrors.eBuildSeqExpectedTrackName);
                }

                /* group */
                Token = Scanner.GetNextToken();
                if ((Token.GetTokenType() != TokenTypes.eTokenKeyword) ||
                    (Token.GetTokenKeywordTag() != SeqKeywordType.eSeqKeywordGroup))
                {
                    ErrorLine = Scanner.GetCurrentLineNumber();
                    return(BuildSeqErrors.eBuildSeqExpectedGroup);
                }

                /* "group" */
                TokenGroup = Scanner.GetNextToken();
                if (TokenGroup.GetTokenType() != TokenTypes.eTokenString)
                {
                    ErrorLine = Scanner.GetCurrentLineNumber();
                    return(BuildSeqErrors.eBuildSeqExpectedGroupName);
                }

                /* ; */
                Token = Scanner.GetNextToken();
                if (Token.GetTokenType() != TokenTypes.eTokenSemicolon)
                {
                    ErrorLine = Scanner.GetCurrentLineNumber();
                    return(BuildSeqErrors.eBuildSeqExpectedSemicolon);
                }

                /* add it */
                AddTrackToSequencerConfigSpec(
                    Sequencer,
                    TokenName.GetTokenStringValue(),
                    TokenGroup.GetTokenStringValue());
            }

            return(BuildSeqErrors.eBuildSeqNoError);
        }
Ejemplo n.º 12
0
 public Token(TokenType type, TokenGroup group)
 {
     Type  = type;
     Group = group;
 }
 // This is a positional argument
 public TokenGroupAttribute(TokenGroup tokenGroup)
 {
     this.tokenGroup = tokenGroup;
 }
Ejemplo n.º 14
0
        /*
         * 
         * [Test]
public void testBigramAnalyzer() {
         * //test to ensure analyzers with none-consecutive start/end offsets //dont
         * double-highlight text //setup index 1 RAMDirectory ramDir = new
         * RAMDirectory(); Analyzer bigramAnalyzer=new CJKAnalyzer(); IndexWriter
         * writer = new IndexWriter(ramDir,bigramAnalyzer , true); Document d = new
         * Document(); Field f = new Field(FIELD_NAME, "java abc def", true, true,
         * true); d.Add(f); writer.AddDocument(d); writer.Close(); IndexReader reader =
         * IndexReader.Open(ramDir, true);
         * 
         * IndexSearcher searcher=new IndexSearcher(reader); query =
         * QueryParser.Parse("abc", FIELD_NAME, bigramAnalyzer);
         * Console.WriteLine("Searching for: " + query.ToString(FIELD_NAME)); hits =
         * searcher.Search(query);
         * 
         * Highlighter highlighter = new Highlighter(this,new
         * QueryFragmentScorer(query));
         * 
         * for (int i = 0; i < hits.TotalHits; i++) { String text =
         * searcher.Doc(hits.ScoreDocs[i].Doc).Get(FIELD_NAME); TokenStream
         * tokenStream=bigramAnalyzer.TokenStream(FIELD_NAME,new StringReader(text));
         * String highlightedText = highlighter.GetBestFragment(tokenStream,text);
         * Console.WriteLine(highlightedText); } }
         */

        public String HighlightTerm(String originalText, TokenGroup group)
        {
            if (@group.TotalScore <= 0)
            {
                return originalText;
            }
            numHighlights++; // update stats used in assertions
            return "<B>" + originalText + "</B>";
        }
Ejemplo n.º 15
0
 public BareToken(TokenKind tk, TokenGroup tp)
 {
     this.tk = tk; this.tp = tp;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MissingTokenException" /> class.
 /// </summary>
 /// <param name="expectedGroup">The expected group.</param>
 /// <param name="foundGroup">The found group.</param>
 /// <param name="production">The production.</param>
 public MissingTokenException(TokenGroup expectedGroup, TokenGroup foundGroup, string production)
     : this(expectedGroup.ToString(), foundGroup.ToString(), production)
 {
 }
        public object GetValue(Option modelOption, TokenGroup tokenGroup)
        {
            object value = tokenGroup.Parameter.Value;

            return(ValueConverter.ConvertValue(value, modelOption.Property.PropertyType));
        }