/// <summary>
        /// Returns a string representation of the object's current attributes
        /// </summary>
        /// <returns>a string representation of the object's current attributes</returns>
        public virtual string DescribeAttributes()
        {
            IStringBuilder sb = TextFactory.CreateStringBuilder();

            sb.Append("[");
            bool first = true;

            foreach (object key in attributes.GetKeys())
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(", ");
                }

                sb.Append(key);
                sb.Append("==");
                sb.Append(attributes.Get(key));
            }
            sb.Append("]");

            return(sb.ToString());
        }
Esempio n. 2
0
        public override string ToString()
        {
            if (cachedStringRep == null)
            {
                IStringBuilder sb    = TextFactory.CreateStringBuilder();
                bool           first = true;
                sb.Append("{");
                foreach (Clause c in clauses)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(", ");
                    }
                    sb.Append(c);
                }
                sb.Append("}");
                cachedStringRep = sb.ToString();
            }

            return(cachedStringRep);
        }
Esempio n. 3
0
        public static StandardizeApartIndexical newStandardizeApartIndexical(char preferredPrefix)
        {
            char ch = preferredPrefix;

            if (!(char.IsLetter(ch) && char.IsLower(ch)))
            {
                throw new IllegalArgumentException("Preferred prefix :"
                                                   + preferredPrefix + " must be a valid a lower case letter.");
            }

            IStringBuilder sb = TextFactory.CreateStringBuilder();
            int            currentPrefixCnt = 0;

            if (!_assignedIndexicals.ContainsKey(preferredPrefix))
            {
                currentPrefixCnt = 0;
            }
            else
            {
                currentPrefixCnt  = _assignedIndexicals.Get(preferredPrefix);
                currentPrefixCnt += 1;
            }
            _assignedIndexicals.Put(preferredPrefix, currentPrefixCnt);
            sb.Append(preferredPrefix);
            for (int i = 0; i < currentPrefixCnt; ++i)
            {
                sb.Append(preferredPrefix);
            }

            return(new StandardizeApartIndexicalImpl(sb.ToString()));
        }
Esempio n. 4
0
        public async Task DrawMaskAsync()
        {
            using (var g = new GraphicsService())
            {
                var d = new CardDetails(Context.Account, Context.User);

                using (Bitmap card = g.DrawCard(d, PaletteType.GammaGreen))
                {
                    using (var factory = new TextFactory())
                    {
                        Grid <float> mask = ImageHelper.GetOpacityMask(card);

                        var pixels = new Grid <Color>(card.Size, new ImmutableColor(0, 0, 0, 255));

                        // TODO: Make ImmutableColor.Empty values
                        pixels.SetEachValue((x, y) =>
                                            ImmutableColor.Blend(new ImmutableColor(0, 0, 0, 255), new ImmutableColor(255, 255, 255, 255),
                                                                 mask.GetValue(x, y)));

                        using (Bitmap masked = ImageHelper.CreateRgbBitmap(pixels.Values))
                            await Context.Channel.SendImageAsync(masked, $"../tmp/{Context.User.Id}_card_mask.png");
                    }
                }
            }
        }
Esempio n. 5
0
        public LoseState(ButtonFactory buttonFactory, TextFactory textFactory, IPostOfficeService postOfficeService, LeaderboardManager leaderboardManager)
        {
            _buttonFactory      = buttonFactory;
            _textFactory        = textFactory;
            _postOfficeService  = postOfficeService;
            _leaderboardManager = leaderboardManager;
            _playerScore        = 0L;

            // Check for 123456 because user cannot enter this
            _playername = "123456";

            // Ready to write to file.
            _ready = true;

            #region Button Stuff

            // Menu button stuff
            var menuArgs = new PostOfficeEventArgs()
            {
                SendAddress = "StateManager",
                MessageName = "ChangeState",
                Data        = Encoding.ASCII.GetBytes("Menu")
            };

            _menuButton = _buttonFactory.GenerateButton("Menu", 20, 400, menuArgs);

            #endregion
        }
Esempio n. 6
0
        // TODO
        // Make more intelligent link search
        public ICollection <string> getOutlinks(Page page)
        {
            string content = page.getContent();
            ICollection <string> outLinks = CollectionFactory.CreateQueue <string>();
            // search content for all href="x" outlinks
            ICollection <string> allMatches = CollectionFactory.CreateQueue <string>();
            IRegularExpression   m          = TextFactory.CreateRegularExpression("href=\"(/wiki/.*?)\"");

            foreach (string ma in m.Matches(content))
            {
                allMatches.Add(ma);
            }
            for (int i = 0; i < allMatches.Size(); ++i)
            {
                string   match    = allMatches.Get(i);
                string[] tokens   = TextFactory.CreateRegularExpression("\"").Split(match);
                string   location = tokens[1].ToLower(); // also, tokens[0] = the
                                                         // text before the first
                                                         // quote,
                                                         // and tokens[2] is the
                                                         // text after the second
                                                         // quote
                outLinks.Add(location);
            }

            return(outLinks);
        }
Esempio n. 7
0
        // string split constructor
        public Rule(string lhs, string rhs, float probability)
        {
            this.lhs = CollectionFactory.CreateQueue <string>();
            this.rhs = CollectionFactory.CreateQueue <string>();

            IRegularExpression regex = TextFactory.CreateRegularExpression("\\s*,\\s*");

            if (!string.IsNullOrEmpty(lhs))
            {
                this.lhs = CollectionFactory.CreateQueue <string>();
                foreach (string input in regex.Split(lhs))
                {
                    if (!string.IsNullOrEmpty(input))
                    {
                        this.lhs.Add(input);
                    }
                }
            }

            if (!string.IsNullOrEmpty(rhs))
            {
                foreach (string input in regex.Split(rhs))
                {
                    if (!string.IsNullOrEmpty(input))
                    {
                        this.rhs.Add(input);
                    }
                }
            }

            this.PROB = validateProb(probability);
        }
Esempio n. 8
0
        public override string ToString()
        {
            IStringBuilder sb    = TextFactory.CreateStringBuilder();
            bool           first = true;

            sb.Append('[');
            foreach (var item in this)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(", ");
                }
                sb.Append('[');
                sb.Append(item.GetKey().ToString());
                sb.Append(", ");
                sb.Append(item.GetValue().ToString());
                sb.Append(']');
            }

            sb.Append(']');
            return(sb.ToString());
        }
Esempio n. 9
0
        /**
         * Returns a string representation of the environment
         *
         * @return a string representation of the environment
         */
        public override string ToString()
        {
            IStringBuilder builder = TextFactory.CreateStringBuilder("{");

            foreach (KeyValuePair <string, VacuumEnvironment.LocationState> entity in state)
            {
                if (builder.GetLength() > 2)
                {
                    builder.Append(", ");
                }
                builder.Append(entity.GetKey()).Append("=").Append(entity.GetValue());
            }
            int i = 0;

            foreach (KeyValuePair <IAgent, string> entity in agentLocations)
            {
                if (builder.GetLength() > 2)
                {
                    builder.Append(", ");
                }
                builder.Append("Loc").Append(++i).Append("=").Append(entity.GetValue());
            }
            builder.Append("}");
            return(builder.ToString());
        }
Esempio n. 10
0
        public IActionResult Post([FromBody] FormModel model)
        {
            if (!ModelState.IsValid || model.Input == null)
            {
                return(BadRequest(ModelState));
            }

            var    text             = TextFactory.GenerateText(model.Input);
            string serializedObject = string.Empty;

            switch (model.Type)
            {
            case Type.Xml:
                serializedObject = xmlService.SerializeObject(text);
                break;

            case Type.Csv:
                serializedObject = csvService.SerializeObject(text);
                break;
            }

            return(Ok(new
            {
                Response = serializedObject
            }));
        }
Esempio n. 11
0
 public Start(ISurveyRepository repository, Facade facade, Player player, TextFactory textFactory)
 {
     _repository  = repository;
     _facade      = facade;
     _player      = player;
     _textFactory = textFactory;
 }
Esempio n. 12
0
        public static Example exampleFromString(string data, DataSetSpecification dataSetSpec, string separator)
        {
            IRegularExpression        splitter        = TextFactory.CreateRegularExpression(separator);
            IMap <string, IAttribute> attributes      = CollectionFactory.CreateInsertionOrderedMap <string, IAttribute>();
            ICollection <string>      attributeValues = CollectionFactory.CreateQueue <string>(splitter.Split(data));

            if (dataSetSpec.isValid(attributeValues))
            {
                ICollection <string> names = dataSetSpec.getAttributeNames();
                int min = names.Size() > attributes.Size() ? names.Size() : attributes.Size();

                for (int i = 0; i < min; ++i)
                {
                    string name = names.Get(i);
                    IAttributeSpecification attributeSpec = dataSetSpec.getAttributeSpecFor(name);
                    IAttribute attribute = attributeSpec.CreateAttribute(attributeValues.Get(i));
                    attributes.Put(name, attribute);
                }
                string targetAttributeName = dataSetSpec.getTarget();
                return(new Example(attributes, attributes.Get(targetAttributeName)));
            }
            else
            {
                throw new RuntimeException("Unable to construct Example from " + data);
            }
        }
Esempio n. 13
0
        public override string ToString()
        {
            if (null == stringRep)
            {
                IStringBuilder sb = TextFactory.CreateStringBuilder();
                sb.Append(functionName);
                sb.Append("(");

                bool first = true;
                foreach (Term t in terms)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }
                    sb.Append(t.ToString());
                }

                sb.Append(")");

                stringRep = sb.ToString();
            }
            return(stringRep);
        }
Esempio n. 14
0
        private Token symbol()
        {
            int            startPosition = getCurrentPositionInInput();
            IStringBuilder sbuf          = TextFactory.CreateStringBuilder();

            while (null != lookAhead(1) && PropositionSymbol.isPropositionSymbolIdentifierPart(lookAhead(1).Value))
            {
                sbuf.Append(lookAhead(1));
                consume();
            }
            string symbol = sbuf.ToString();

            if (PropositionSymbol.isAlwaysTrueSymbol(symbol))
            {
                return(new Token(LogicTokenTypes.TRUE, PropositionSymbol.TRUE_SYMBOL, startPosition));
            }
            else if (PropositionSymbol.isAlwaysFalseSymbol(symbol))
            {
                return(new Token(LogicTokenTypes.FALSE, PropositionSymbol.FALSE_SYMBOL, startPosition));
            }
            else if (PropositionSymbol.isPropositionSymbol(symbol))
            {
                return(new Token(LogicTokenTypes.SYMBOL, sbuf.ToString(), startPosition));
            }

            throw new LexerException("Lexing error on symbol " + symbol + " at position " + getCurrentPositionInInput(), getCurrentPositionInInput());
        }
Esempio n. 15
0
        public override string ToString()
        {
            IStringBuilder sb = TextFactory.CreateStringBuilder();

            sb.Append("#");
            sb.Append(posHeads.Size());
            foreach (string key in posHeads.GetKeys())
            {
                sb.Append(",");
                sb.Append(posHeads.Get(key).Size());
            }
            sb.Append(" posHeads=");
            sb.Append(posHeads.ToString());
            sb.Append("\n");
            sb.Append("#");
            sb.Append(negHeads.Size());
            foreach (string key in negHeads.GetKeys())
            {
                sb.Append(",");
                sb.Append(negHeads.Get(key).Size());
            }
            sb.Append(" negHeads=");
            sb.Append(negHeads.ToString());

            return(sb.ToString());
        }
Esempio n. 16
0
        /// <summary>
        /// Utility method for outputting proofs in a formatted textual
        /// representation.
        /// </summary>
        /// <param name="proof"></param>
        /// <returns></returns>
        public static string printProof(Proof proof)
        {
            IStringBuilder sb = TextFactory.CreateStringBuilder();

            sb.Append("Proof, Answer Bindings: ");
            sb.Append(proof.getAnswerBindings());
            sb.Append("\n");

            ICollection <ProofStep> steps = proof.getSteps();

            int maxStepWidth          = "Step".Length;
            int maxProofWidth         = "Proof".Length;
            int maxJustificationWidth = "Justification".Length;

            // Calculate the maximum width for each column in the proof
            foreach (ProofStep step in steps)
            {
                string sn = "" + step.getStepNumber();
                if (sn.Length > maxStepWidth)
                {
                    maxStepWidth = sn.Length;
                }
                if (step.getProof().Length > maxProofWidth)
                {
                    maxProofWidth = step.getProof().Length;
                }
                if (step.getJustification().Length > maxJustificationWidth)
                {
                    maxJustificationWidth = step.getJustification().Length;
                }
            }

            // Give a little extra padding
            maxStepWidth          += 1;
            maxProofWidth         += 1;
            maxJustificationWidth += 1;

            string f = "|{0}-" + maxStepWidth + "s| {1}-" + maxProofWidth + "s|{2}-" + maxJustificationWidth + "s|\n";

            int            barWidth = 5 + maxStepWidth + maxProofWidth + maxJustificationWidth;
            IStringBuilder bar      = TextFactory.CreateStringBuilder();

            for (int i = 0; i < barWidth; ++i)
            {
                bar.Append("-");
            }
            bar.Append("\n");

            sb.Append(bar);
            sb.Append(string.Format(f, "Step", "Proof", "Justification"));
            sb.Append(bar);
            foreach (ProofStep step in steps)
            {
                sb.Append(string.Format(f, "" + step.getStepNumber(), step.getProof(), step.getJustification()));
            }
            sb.Append(bar);

            return(sb.ToString());
        }
Esempio n. 17
0
        private Stream DrawFrame(TextFactory graphics, string content, Color color, ImageProperties properties = null)
        {
            var stream = new MemoryStream();

            using Bitmap frame = graphics.DrawText(content, color, properties);
            frame.Save(stream, ImageFormat.Png);
            return(stream);
        }
Esempio n. 18
0
        public void GenerateText_ShouldReturnNull_WhenInputIsNull()
        {
            //Act
            var result = TextFactory.GenerateText(null);

            //Assert
            Assert.Null(result);
        }
        public void setUp()
        {
            envChanges = TextFactory.CreateStringBuilder();

            BidirectionalSearch <string, MoveToAction> bidirectionalSearch = new BidirectionalSearch <string, MoveToAction>();

            search = new BreadthFirstSearch <string, MoveToAction>(bidirectionalSearch);
        }
Esempio n. 20
0
 public override void Setup(World world, out ISystem <float> systems)
 {
     _imageFactory  = new ImageFactory(world);
     _buttonFactory = new ButtonFactory(world, _game.GraphicsDevice);
     _textFactory   = new TextFactory(world);
     InitializeSystems(world, out systems);
     SetupWorld(world);
 }
Esempio n. 21
0
    public void changeHealth(buffDelegate method, int amount, TextType type)
    {
        method.Invoke(amount);

        Vector3 v = new Vector3(transform.position.x, transform.position.y, transform.position.z);

        TextFactory.getInstance().createMovingText(damageTextPrefab, v, amount, type, true);
        updateHealthBar();
    }
Esempio n. 22
0
            public override string ToString()
            {
                IStringBuilder sb = TextFactory.CreateStringBuilder();

                sb.Append("isComplete=" + complete);
                sb.Append("\n");
                sb.Append("result=" + proofs);
                return(sb.ToString());
            }
        public override string ToString()
        {
            IStringBuilder sb = TextFactory.CreateStringBuilder();

            sb.Append('[');
            sb.Append(name);
            sb.Append("]");
            return(sb.ToString());
        }
Esempio n. 24
0
        public async Task CycleTimeAsync(int framesPerHour = 1, int delay = 150, int?loop = null)
        {
            string   path = $"../tmp/{Context.User.Id}_time.gif";
            FontFace font = JsonHandler.Load <FontFace>(@"../assets/fonts/orikos.json");

            char[][][][] charMap = JsonHandler.Load <char[][][][]>(@"../assets/char_map.json", new JsonCharArrayConverter());
            var          config  = TextFactoryConfig.Default;

            config.CharMap = charMap;

            var frames     = new List <Stream>();
            var properties = new ImageProperties
            {
                TrimEmptyPixels = true,
                Padding         = new Padding(2),
                Width           = 47
            };

            float t = 0.00f;

            using (var factory = new TextFactory(config))
            {
                factory.SetFont(font);

                for (float h = 0; h < 24 * framesPerHour; h++)
                {
                    GammaPalette colors = TimeCycle.FromHour(t);
                    properties.Matte = colors[Gamma.Min];

                    frames.Add(DrawFrame(factory, t.ToString("00.00H"), colors[Gamma.Max], properties));

                    t += (1.00f / framesPerHour);
                }
            }

            var gifStream = new MemoryStream();

            using (var encoder = new GifEncoder(gifStream, repeatCount: loop))
            {
                encoder.FrameLength = TimeSpan.FromMilliseconds(delay);

                foreach (Stream frame in frames)
                {
                    await using (frame)
                        encoder.EncodeFrame(Image.FromStream(frame));
                }
            }

            gifStream.Position = 0;
            Image gifResult = Image.FromStream(gifStream);

            gifResult.Save(path, ImageFormat.Gif);
            await gifStream.DisposeAsync();

            await Context.Channel.SendFileAsync(path);
        }
Esempio n. 25
0
        public override string ToString()
        {
            IStringBuilder sb = TextFactory.CreateStringBuilder();

            sb.Append(key)
            .Append("==")
            .Append(value);

            return(sb.ToString());
        }
Esempio n. 26
0
        public static string ntimes(string s, int n)
        {
            IStringBuilder builder = TextFactory.CreateStringBuilder();

            for (int i = 0; i < n; ++i)
            {
                builder.Append(s);
            }
            return(builder.ToString());
        }
        /**
         * Template method controlling the search. It is based on iterative
         * deepening and tries to make to a good decision in limited time. Credit
         * goes to Behi Monsio who had the idea of ordering actions by utility in
         * subsequent depth-limited search runs.
         */

        public virtual A makeDecision(S state)
        {
            metrics = new Metrics();
            IStringBuilder logText = null;
            P player = game.GetPlayer(state);
            ICollection <A> results = orderActions(state, game.GetActions(state), player, 0);

            timer.start();
            currDepthLimit = 0;
            do
            {
                incrementDepthLimit();
                if (logEnabled)
                {
                    logText = TextFactory.CreateStringBuilder("depth " + currDepthLimit + ": ");
                }
                heuristicEvaluationUsed = false;
                ActionStore newResults = new ActionStore();
                foreach (A action in results)
                {
                    double value = minValue(game.GetResult(state, action), player, double.NegativeInfinity,
                                            double.PositiveInfinity, 1);
                    if (timer.timeOutOccurred())
                    {
                        break; // exit from action loop
                    }
                    newResults.add(action, value);
                    if (logEnabled)
                    {
                        logText.Append(action).Append("->").Append(value).Append(" ");
                    }
                }
                if (logEnabled)
                {
                    System.Console.WriteLine(logText);
                }
                if (newResults.size() > 0)
                {
                    results = newResults.actions;
                    if (!timer.timeOutOccurred())
                    {
                        if (hasSafeWinner(newResults.utilValues.Get(0)))
                        {
                            break; // exit from iterative deepening loop
                        }
                        else if (newResults.size() > 1 &&
                                 isSignificantlyBetter(newResults.utilValues.Get(0), newResults.utilValues.Get(1)))
                        {
                            break; // exit from iterative deepening loop
                        }
                    }
                }
            } while (!timer.timeOutOccurred() && heuristicEvaluationUsed);
            return(results.Get(0));
        }
Esempio n. 28
0
        public void setUp()
        {
            aMap = new ExtendableMap();
            aMap.addBidirectionalLink("A", "B", 5.0);
            aMap.addBidirectionalLink("A", "C", 6.0);
            aMap.addBidirectionalLink("B", "C", 4.0);
            aMap.addBidirectionalLink("C", "D", 7.0);
            aMap.addUnidirectionalLink("B", "E", 14.0);

            envChanges = TextFactory.CreateStringBuilder();
        }
Esempio n. 29
0
        public override string ToString()
        {
            IStringBuilder buf = TextFactory.CreateStringBuilder();

            foreach (DecisionListTest test in tests)
            {
                buf.Append(test.ToString() + " => " + testOutcomes.Get(test) + " ELSE \n");
            }
            buf.Append("END");
            return(buf.ToString());
        }
Esempio n. 30
0
        public override string ToString()
        {
            IStringBuilder sb = TextFactory.CreateStringBuilder();

            foreach (Sentence s in originalSentences)
            {
                sb.Append(s.ToString());
                sb.Append("\n");
            }
            return(sb.ToString());
        }