private string SerializeCity()
 {
     return(string.Join("|", Constituents.Select((c) =>
     {
         return c.party.ToString() + "-" + c.District.name;
     }).ToArray()));
 }
Exemple #2
0
        public override Production Parse(List <Token> tokens)
        {
            var symbolToken = tokens.First();

            if (symbolToken.TokenClass != TokenClass.Symbol)
            {
                return(new Production(null, tokens));
            }
            var symbol    = new SymbolExpression().Parse(tokens);
            var remaining = symbol.RemainingTokens;

            //function has to have parameters
            if (symbol.Expression == null || remaining.None())
            {
                return(new Production(null, tokens));
            }
            Constituents.Add(symbol.Expression);
            var separated = new SeparatedExpression().Parse(symbol.RemainingTokens);

            if (separated.Expression != null)
            {
                Constituents.Add(separated.Expression);
                return(new Production(this, separated.RemainingTokens));
            }
            var scoped = new ScopedExpression().Parse(symbol.RemainingTokens);

            if (scoped.Expression == null)
            {
                return(new Production(null, tokens));
            }
            Constituents.Add(scoped.Expression);
            return(new Production(this, scoped.RemainingTokens));
        }
    private void BalanceConstituentCounts()
    {
        var RedConstituents  = Constituents.Where((c) => c.party == Constituent.Party.Red);
        var BlueConstituents = Constituents.Where((c) => c.party == Constituent.Party.Blue);

        var RedCount  = RedConstituents.Count();
        var BlueCount = BlueConstituents.Count();

        HashSet <District> changedDistricts = new HashSet <District>();

        if (RedCount > BlueConstituents.Count())
        {
            //find the disparity, and convert half that many to blue
            int diff = RedCount - BlueCount;

            //if diff is odd, convert one red to brown
            if ((diff % 2) == 1)
            {
                Constituent c = Utils.ChooseRandom(RedConstituents.ToList());
                c.party = Constituent.Party.Yellow;
                changedDistricts.Add(c.District);
            }

            //choose enough constituents randomly to even things out, and convert them to the other party
            foreach (Constituent c in Utils.ChooseKRandom(RedConstituents.ToList(), diff / 2))
            {
                c.party = Constituent.Party.Blue;
                changedDistricts.Add(c.District);
            }
        }
        else if (RedCount < BlueCount)
        {
            //find the disparity, and convert half that many to red
            int diff = BlueCount - RedCount;

            //if diff is odd, convert one red to brown
            if ((diff % 2) == 1)
            {
                Constituent c = Utils.ChooseRandom(RedConstituents.ToList());
                c.party = Constituent.Party.Yellow;
                changedDistricts.Add(c.District);
            }

            //choose enough constituents randomly to even things out, and convert them to the other party

            foreach (Constituent c in Utils.ChooseKRandom(BlueConstituents.ToList(), diff / 2))
            {
                c.party = Constituent.Party.Red;
                changedDistricts.Add(c.District);
            }
        }

        //update the member counts of every district we changed
        foreach (District d in changedDistricts)
        {
            d.UpdateMemberData();
        }
    }
Exemple #4
0
        /// <summary>
        /// Returns a string representation of the aggregate entity.
        /// </summary>
        /// <returns>A string representation of the aggregate entity.</returns>
        public override string ToString()
        {
            var members = Constituents.ToList();

            return($@"[ {members.Count} ] {string.Join(" ",
                from member in members
                where !(member is IAggregateEntity)
                select $"{member.GetType().Name} \"{member.Text}\"")
            }");
        }
Exemple #5
0
        void addConstituent()
        {
            var constit = new CarbonMaterials.CementAndConcreteConstituent
            {
                Material   = ICE3CementModel.getCementConstituents()["Aggregates"],
                Proportion = 0
            };

            (_material as CarbonMaterials.ICE3ConcreteModel).Constituents.Add(constit);
            Constituents.Add(new ConstituentVM(constit, this));
        }
        public JsonResult Search(SearchModel searchCriteria)
        {
            var uriString = string.Format(serviceBaseUri + @"/Search?firstName={0}&lastName={1}&email={2}&phone={3}&occupationName={4}&occupationDescription={5}&instituteName={6}&instituteLocation={7}&qualification={8}&yearOfGradutation={9}&address={10}&state={11}&city={12}&country={13}&postcode={14}&preferedName={15}&houseName={16}&branch={17}&matchAllCriteria={18}"
                                          ,searchCriteria.FirstName, searchCriteria.LastName,searchCriteria.Email,searchCriteria.Phone,searchCriteria.OccupationName,searchCriteria.OccupationDescription
                                          ,searchCriteria.InstituteName,searchCriteria.InstituteLocation,searchCriteria.Qualification,searchCriteria.YearOfGraduation
                                          ,searchCriteria.Address,searchCriteria.State,searchCriteria.City,searchCriteria.Country,searchCriteria.Postcode
                                          ,searchCriteria.PreferedName,searchCriteria.HouseName,searchCriteria.Branch,true);
            var constituentsData = HttpHelper.Get<ConstituentsData>(uriString);

            mapper = new AutoDataContractMapper();
            var constituents = new Constituents();
            mapper.MapList(constituentsData, constituents,typeof(Constituent));
            ViewData["Constituents"] = constituents;

            return this.Json(constituents);
        }
Exemple #7
0
        /// <summary>Return a new <see cref="ParseResult"/> constructed from <paramref name="annotation"/></summary>
        internal ParseResult(Annotation annotation)
        {
            java.util.AbstractList sentences = annotation.get(SentencesAnnotationClass) as java.util.AbstractList;
            CoreMap sentence = sentences.get(0) as CoreMap;
            LabeledScoredTreeNode constituencyParse = sentence.get(TreeAnnotationClass) as LabeledScoredTreeNode;
            // Skip the ROOT
            Tree childOfRoot = constituencyParse.firstChild();

            Constituents = childOfRoot;
            Constituents.indexLeaves();

            // Build the collection of tokens
            var parsedTokens = sentence.get(TokensAnnotationClass) as java.util.AbstractList;
            var mentions     = sentence.get(MentionsAnnotationClass);

            for (int tokenIndex = 0; tokenIndex < parsedTokens.size(); tokenIndex++)
            {
                CoreLabel source        = parsedTokens.get(tokenIndex) as CoreLabel;
                var       tokenMentions = source.get(MentionTokenAnnotationClass);
                var       tokenGender   = source.get(GenderAnnotationClass);
                Tokens.Add(new ParseToken
                {
                    Index            = source.index(),
                    Word             = source.word(),
                    Lemma            = source.lemma(),
                    PartOfSpeech     = source.get(PartOfSpeechAnnotationClass) as string,
                    NamedEntityClass = source.get(NamedEntityTagAnnotationClass) as string,
                });
            }

            // Create the list of dependencies between tokens
            SemanticGraph dependencyGraph = sentence.get(DependencyAnnotationClass) as SemanticGraph;

            //java.util.List dependencies = dependencyGraph.edgeListSorted();
            java.util.Iterator dependencyGraphEdges = dependencyGraph.edgeIterable().iterator();
            while (dependencyGraphEdges.hasNext())
            {
                SemanticGraphEdge edge = dependencyGraphEdges.next() as SemanticGraphEdge;

                string      relationName      = edge.getRelation().getShortName();
                string      relationSpecifier = edge.getRelation().getSpecific();
                IndexedWord governor          = edge.getGovernor();
                IndexedWord dependent         = edge.getDependent();

                Dependencies.Add((relationName, relationSpecifier, governor.index(), dependent.index()));
            }
        }
Exemple #8
0
        //for editing Purok Leader
        private void LoadAllPersons()
        {
            Constituents.Clear();
            var households = _repository.Household.GetRange(c => c.PurokNo == Model.PurokNo);

            MaleCount   = 0;
            FemaleCount = 0;
            foreach (var household in households)
            {
                var persons = _repository.Person.GetRange(c => c.HouseNo == household.HouseNo);

                foreach (var person in persons)
                {
                    //var singlePerson = _repository.Person.Get(c => c.PersonId == person.PersonId);
                    try
                    {
                        if (person.Gender.Equals("Male"))
                        {
                            MaleCount++;
                        }
                        else if (person.Gender.Equals("Female"))
                        {
                            FemaleCount++;
                        }
                    }
                    catch (Exception e) { }

                    Constituents.Add(new PersonModel(person, _repository));

                    if (person.IsPurokHead == true)
                    {
                        PurokHead = new PersonModel(person, _repository);
                    }
                }
            }
        }
        public ActionResult GetConstituent(string text)
        {
            Thread.Sleep(1000);
            var uriString = string.Format(serviceBaseUri + @"/Search?firstName={0}&lastName={0}&email={1}&phone={1}&occupationName={1}&occupationDescription={1}&instituteName={1}&instituteLocation={1}&qualification={1}&yearOfGradutation={1}&address={1}&state={1}&city={1}&country={1}&postcode={1}&preferedName={0}&houseName={1}&branch={1}", text,null);
            var constituentsData = HttpHelper.Get<ConstituentsData>(uriString);
            mapper = new AutoDataContractMapper();
            var constituents = new Constituents();
            mapper.MapList(constituentsData, constituents, typeof(Constituent));
            IEnumerable<Constituent> enumerable = null;
            if (text.HasValue())
            {
                enumerable = constituents.Where((p) => p.Name.FirstName.StartsWith(text,true,null) || p.Name.LastName.StartsWith(text,true,null));
            }

            IEnumerable<SelectListItem> selectList =
                                                    from c in enumerable
                                                    select new SelectListItem
                                                    {
                                                        Text = c.Name.NameWithoutSalutation,
                                                        Value = c.Id.ToString()
                                                    };

            return new JsonResult { Data = selectList };
        }
        private Constituents PopulateSearchResults(string id)
        {
            var uriString = serviceBaseUri + "/SearchUnRegistered?constituentId=" + id;
            var constituentsData = HttpHelper.Get<ConstituentsData>(uriString);

            mapper = new AutoDataContractMapper();
            var constituents = new Constituents();
            mapper.MapList(constituentsData, constituents, typeof (Constituent));

            return constituents;
        }
        private Constituents GetRegistrations()
        {
            var constituentsData = HttpHelper.Get<ConstituentsData>(serviceBaseUri + "/Registrations");

            mapper = new AutoDataContractMapper();
            var constituents = new Constituents();
            mapper.MapList(constituentsData, constituents, typeof (Constituent));
            return constituents;
        }
Exemple #12
0
 public override EvaluationResult Evaluate(NumericPrecision numericPrecision, ValueSource values, FunctionSource functions)
 => Constituents.Select(c => c.Evaluate(numericPrecision, values, functions)).ToList();
Exemple #13
0
        public override Production Parse(List <Token> tokens)
        {
            var firstParen = tokens.First();

            if (firstParen.TokenClass != TokenClass.StartScope)
            {
                return(new Production(null, tokens));
            }
            var current   = new ScopeExpression().Parse(tokens);
            var remaining = current.RemainingTokens.ToList();

            while (remaining.Any() && remaining.FirstOrDefault() != null && remaining[0].TokenClass != TokenClass.EndScope)
            {
                switch (remaining.First().TokenClass)
                {
                case TokenClass.ReplacementSymbol:
                    if (Constituents.Count > 1 && !(Constituents.Last() is SeparatorExpression))
                    {
                        return(new Production(null, tokens));
                    }
                    current = new ReplacementSymbolExpression().Parse(remaining);
                    break;

                case TokenClass.Integer:
                case TokenClass.Float:
                    if (Constituents.Count > 1 && !(Constituents.Last() is SeparatorExpression))
                    {
                        return(new Production(null, tokens));
                    }
                    current = NumericExpression.TryParseNumeric(remaining);
                    break;

                case TokenClass.String:
                    if (Constituents.Count > 1 && !(Constituents.Last() is SeparatorExpression))
                    {
                        return(new Production(null, tokens));
                    }
                    current = new StringExpression().Parse(remaining);
                    break;

                case TokenClass.Boolean:
                    if (Constituents.Count > 1 && !(Constituents.Last() is SeparatorExpression))
                    {
                        return(new Production(null, tokens));
                    }
                    current = new BooleanExpression().Parse(remaining);
                    break;

                case TokenClass.Symbol:
                    if (Constituents.Count > 1 && !(Constituents.Last() is SeparatorExpression))
                    {
                        return(new Production(null, tokens));
                    }
                    current = new FunctionExpression().Parse(remaining);;
                    if (current.Expression != null)
                    {
                        break;
                    }
                    current = new SymbolExpression().Parse(remaining);
                    break;

                case TokenClass.StartScope:
                    if (Constituents.Count > 1 && !(Constituents.Last() is SeparatorExpression))
                    {
                        return(new Production(null, tokens));
                    }
                    current = new SeparatedExpression().Parse(remaining);
                    if (current.Expression != null)
                    {
                        break;
                    }
                    current = new ScopedExpression().Parse(remaining);
                    if (current.Expression != null)
                    {
                        break;
                    }
                    break;

                case TokenClass.EndScope:
                    current = new ScopeExpression().Parse(remaining);
                    break;

                case TokenClass.Whitespace:
                    current = new WhitespaceExpression().Parse(remaining);
                    break;

                case TokenClass.Separator:
                    current = new SeparatorExpression().Parse(remaining);
                    break;

                case TokenClass.Operator:
                    if (Constituents.Count < 1 || (Constituents.Last() is SeparatorExpression))
                    {
                        return(new Production(null, remaining));
                    }
                    current = new OperationExpression().Parse(Constituents.Last(), remaining);
                    if (current.Expression == null)
                    {
                        break;
                    }
                    Constituents.RemoveAt(Constituents.Count - 1);
                    break;

                default:
                    return(new Production(null, remaining));
                }
                if (current.Expression == null)
                {
                    return(new Production(null, tokens));
                }
                if (!(current.Expression is WhitespaceExpression))
                {
                    Constituents.Add(current.Expression);
                }
                remaining = current.RemainingTokens;
            }
            //parenthesis must be closed
            if (remaining.FirstOrDefault() == null || remaining.First().TokenClass != TokenClass.EndScope)
            {
                return(new Production(null, remaining));
            }
            var separators = Constituents.Count(c => c is SeparatorExpression);
            var values     = Constituents.Count(c => !(c is SeparatorExpression));

            //cannot be a separated expression without separators
            if (separators == 0)
            {
                return(new Production(null, tokens));
            }
            //separated expressions require exactly n - 1 separators to values
            if (separators != (values - 1))
            {
                return(new Production(null, tokens));
            }
            var valuesOnly = Constituents.ToList().Aggregate(new List <Expression>(), (acc, i) =>
            {
                if (i is ScopeExpression || i is SeparatorExpression)
                {
                    return(acc);
                }
                acc.Add(i);
                return(acc);
            }).ToList();

            Constituents = valuesOnly;
            return(new Production(this, remaining.Skip(1).ToList()));
        }
 public override string ToString()
 {
     return("(" + Constituents.StringConcat() + ")");
 }
 public override EvaluationResult Evaluate(NumericPrecision numericPrecision, ValueSource values, FunctionSource functions)
 => Constituents.Any() ? Constituents[0].Evaluate(numericPrecision, values, functions) : new EvaluationResult(EvaluationType.Null, null);
Exemple #16
0
        public override Production Parse(List <Token> tokens)
        {
            var nonWhitespace = tokens.NextNonWhitespace();

            if (nonWhitespace.TokenClass != TokenClass.Boolean &&
                nonWhitespace.TokenClass != TokenClass.Float &&
                nonWhitespace.TokenClass != TokenClass.Integer &&
                nonWhitespace.TokenClass != TokenClass.ReplacementSymbol &&
                nonWhitespace.TokenClass != TokenClass.StartScope &&
                nonWhitespace.TokenClass != TokenClass.String &&
                nonWhitespace.TokenClass != TokenClass.Symbol)
            {
                return(new Production(null, tokens));
            }
            var remainder = tokens.ToList();

            while (remainder.Any() && Constituents.Count < 3) // An operation must have exactly three items: value op value
            {
                var        currentToken = remainder.First().TokenClass;
                Production current      = null;
                //check whether the right hand side of the operation is another operation
                if (Constituents.Count == 2)
                {
                    current = new OperationExpression().Parse(remainder);
                }
                if (Constituents.Count != 2 || current?.Expression == null)
                {
                    switch (currentToken)
                    {
                    case TokenClass.StartScope:
                        current = new ScopedExpression().Parse(remainder);
                        break;

                    case TokenClass.Whitespace:
                        current = new WhitespaceExpression().Parse(remainder);
                        break;

                    case TokenClass.ReplacementSymbol:
                        current = new ReplacementSymbolExpression().Parse(remainder);
                        break;

                    case TokenClass.Symbol:
                        current = new FunctionExpression().Parse(remainder);
                        if (current.Expression == null)
                        {
                            current = new SymbolExpression().Parse(remainder);
                        }
                        break;

                    case TokenClass.Operator:
                        if (Constituents.Count == 2)
                        {
                            current = NumericExpression.TryParseNumeric(remainder);
                            break;
                        }
                        current = new OperatorExpression().Parse(remainder);
                        break;

                    case TokenClass.Integer:
                    case TokenClass.Float:
                        current = NumericExpression.TryParseNumeric(remainder);
                        break;

                    case TokenClass.String:
                        current = new StringExpression().Parse(remainder);
                        break;

                    case TokenClass.Boolean:
                        current = new BooleanExpression().Parse(remainder);
                        break;

                    default:
                        return(new Production(null, tokens));
                    }
                }
                if (current == null || current.Expression == null)
                {
                    return(new Production(null, tokens));
                }
                remainder = current.RemainingTokens;
                if (!(current.Expression is WhitespaceExpression))
                {
                    Constituents.Add(current.Expression);
                }
            }
            if (Constituents.None(c => c is OperatorExpression))
            {
                return(new Production(null, tokens));
            }
            if (Constituents.Count != 3)
            {
                return(new Production(null, tokens));
            }
            return(new Production(this, remainder));
        }
 public Production Parse(Expression successfullyParsed, List <Token> tokens)
 {
     Constituents.Add(successfullyParsed);
     ErroneousTokens = tokens;
     return(new Production(this, new List <Token>()));
 }
        public override Production Parse(List <Token> tokens)
        {
            var firstParen = tokens.First();

            if (firstParen.TokenClass != TokenClass.StartScope)
            {
                return(new Production(null, tokens));
            }
            var current   = new ScopeExpression().Parse(tokens);
            var remaining = current.RemainingTokens.ToList();

            while (remaining.Any() && remaining.FirstOrDefault() != null && remaining[0].TokenClass != TokenClass.EndScope)
            {
                Expression parsed;
                switch (remaining.First().TokenClass)
                {
                case TokenClass.ReplacementSymbol:
                    current = new OperationExpression().Parse(remaining);
                    if (current.Expression != null)
                    {
                        break;
                    }
                    if (Constituents.Count > 0)
                    {
                        return(new Production(null, tokens));                            //cannot have multiple value types in a row
                    }
                    current = new ReplacementSymbolExpression().Parse(remaining);
                    break;

                case TokenClass.Integer:
                case TokenClass.Float:
                    current = new OperationExpression().Parse(remaining);
                    if (current.Expression != null)
                    {
                        break;
                    }
                    if (Constituents.Count > 0)
                    {
                        return(new Production(null, tokens));
                    }
                    current = NumericExpression.TryParseNumeric(remaining);
                    break;

                case TokenClass.String:
                    current = new OperationExpression().Parse(remaining);
                    if (current.Expression != null)
                    {
                        break;
                    }
                    if (Constituents.Count > 0)
                    {
                        return(new Production(null, tokens));
                    }
                    current = new StringExpression().Parse(remaining);
                    break;

                case TokenClass.Boolean:
                    current = new OperationExpression().Parse(remaining);
                    if (current.Expression != null)
                    {
                        break;
                    }
                    if (Constituents.Count > 0)
                    {
                        return(new Production(null, tokens));
                    }
                    current = new BooleanExpression().Parse(remaining);
                    break;

                case TokenClass.Symbol:
                    current = new FunctionExpression().Parse(remaining);
                    if (current.Expression != null)
                    {
                        break;
                    }
                    if (Constituents.Count > 0)
                    {
                        return(new Production(null, tokens));
                    }
                    current = new SymbolExpression().Parse(remaining);
                    break;

                case TokenClass.StartScope:
                    current = new SeparatedExpression().Parse(remaining);
                    if (current.Expression != null)
                    {
                        break;
                    }
                    if (Constituents.Count > 0)
                    {
                        return(new Production(null, tokens));
                    }
                    current = new ScopedExpression().Parse(remaining);
                    break;

                case TokenClass.Whitespace:
                    current = new WhitespaceExpression().Parse(remaining);
                    break;

                case TokenClass.Operator:
                    if (Constituents.Count != 1)
                    {
                        return(new Production(null, remaining));
                    }
                    current = new OperationExpression().Parse(Constituents.First(), remaining);
                    if (current.Expression == null)
                    {
                        break;
                    }
                    Constituents.Clear();
                    break;

                default:
                    return(new Production(null, remaining));

                    break;
                }
                if (current.Expression == null)
                {
                    return(new Production(null, tokens));
                }
                if (!(current.Expression is WhitespaceExpression))
                {
                    Constituents.Add(current.Expression);
                }
                remaining = current.RemainingTokens;
            }
            if (remaining.None())
            {
                return(new Production(null, tokens));
            }
            if (remaining[0].TokenClass != TokenClass.EndScope)
            {
                return(new Production(null, tokens));
            }
            return(new Production(this, remaining.Skip(1).ToList()));
        }
Exemple #19
0
 /// <summary>
 /// Returns an enumerator that iterates through the members of the aggregate entity.
 /// </summary>
 /// <returns>An enumerator that iterates through the members of the aggregate entity.</returns>
 public IEnumerator <IEntity> GetEnumerator() => Constituents.GetEnumerator();