Exemplo n.º 1
0
        public static IEnumerable <IExpression> SpecializeToCommonTypes(this IEnumerable <IExpression> exprs,
                                                                        out IEnumerable <Type> specializedTypes, out IEnumerable <IExpression> specializedExpressions)
        {
            specializedTypes = null;
            var allExpressions = new HashSet <IExpression>();

            specializedExpressions = allExpressions;

            foreach (var expr in exprs)
            {
                if (specializedTypes == null)
                {
                    specializedTypes = expr.Types;
                }
                else
                {
                    var newlySpecialized = Typs.WidestCommonTypes(specializedTypes, expr.Types);
                    if (!newlySpecialized.Any())
                    {
                        throw new ArgumentException("Could not find a common ground for types " + specializedTypes.Pretty() + " and " + expr.Types.Pretty());
                    }

                    specializedTypes = newlySpecialized;
                }
            }

            foreach (var expr in exprs)
            {
                var e = expr.Specialize(specializedTypes);
                allExpressions.Add(e);
            }

            return(specializedExpressions = allExpressions);
        }
Exemplo n.º 2
0
 protected Type(string name, bool isBuiltin)
 {
     Name = name;
     if (isBuiltin)
     {
         Typs.AddBuiltin(this);
     }
 }
Exemplo n.º 3
0
        public void WidestCommonGround_StringAndString_String()
        {
            var v = Typs.WidestCommonType(Typs.String, Typs.String);

            Assert.NotNull(v);
            var(x, subsTable) = v.Value;
            Assert.NotNull(x);
            Assert.Equal(
                Typs.String, x
                );
        }
Exemplo n.º 4
0
        public void WidestCommonGround_A2PdoubleAndT2Double_T2Double()
        {
            var v = Typs.WidestCommonType(new Curry(new Var("a"), Typs.PDouble),
                                          new Curry(Typs.Tags, Typs.Double)
                                          );

            Assert.NotNull(v);
            var(x, subsTable) = v.Value;
            Assert.NotNull(x);
            Assert.Equal(
                new Curry(Typs.Tags, Typs.Double), x
                );
        }
Exemplo n.º 5
0
        public void EditVechicle(VechicleViewModel vechicle)
        {
            var editVehicle = Inventorys.Include("Mdles").Include("Typs").Include("BodyStyles")
                              .Include("Transmissions").Include("Colors").Include("Interiors")
                              .Include("PurchaseTypes").FirstOrDefault(p => p.Id == vechicle.InventoryId);

            editVehicle.Id           = vechicle.InventoryId;
            editVehicle.Mdles.MakeId = Makes.FirstOrDefault(p => p.MakeName == vechicle.Make).MakeId;
            editVehicle.MdleId       = Models.FirstOrDefault(p => p.ModelName == vechicle.Model).MdleId;

            editVehicle.BodyStyleId    = BodyStyles.FirstOrDefault(p => p.BodyStyleName == vechicle.BodyStyle).BodyStyleId;
            editVehicle.ColorId        = Colors.SingleOrDefault(p => p.ColorName == vechicle.Color).ColorId;
            editVehicle.TypId          = Typs.SingleOrDefault(p => p.TypeName == vechicle.Type).TypId;
            editVehicle.Year           = vechicle.Year;
            editVehicle.TransmissionId = Transmissions.SingleOrDefault(p => p.TransmissionName == vechicle.Transmission).TransmissionId;
            editVehicle.InteriorId     = Interiors.FirstOrDefault(p => p.InteriorName == vechicle.Interior).InteriorId;
            editVehicle.Mileage        = vechicle.Mileage;
            editVehicle.VIN            = vechicle.VIN;
            editVehicle.MSRP           = vechicle.MSRP;
            editVehicle.SalesPrice     = vechicle.SalesPrice;
            editVehicle.Description    = vechicle.Description;

            editVehicle.FeatureVehicle = vechicle.FeatureVehicle;
            if (editVehicle.Picture != null)
            {
                var    oldFile = editVehicle.Picture;
                string path    = Path.Combine(HttpContext.Current.Server.MapPath("~/Images"),
                                              Path.GetFileName(oldFile));
                File.Delete(path);
            }

            if (vechicle.File != null && vechicle.File.ContentLength > 0)
            {
                string[] fileName = vechicle.File.FileName.Split('.');
                string   newName  = "inventory-" + editVehicle.Id + "." + fileName.Last();


                string path = Path.Combine(HttpContext.Current.Server.MapPath("~/Images"),
                                           Path.GetFileName(newName));

                vechicle.File.SaveAs(path);
                editVehicle.Picture = newName;
            }



            (this).SaveChanges();
        }
Exemplo n.º 6
0
 public Int64 Erstellen(List <Int64> typen)
 {
     using (var context = new Context())
     {
         foreach (Int64 id in typen)
         {
             Typ typ = context.Typs.FirstOrDefault(t => t.ID_Typ == id);
             Typs.Add(typ);
         }
         context.Pokemons.Add(this);
         //TODO Check ob mit null möglich, sonst throw Ex
         //if (FremdschluesselListe_Typ != null) context.Typ.Attach(FremdschluesselListe_Typ);
         context.SaveChanges();
         return(this.Nr_Pokemon);
     }
 }
Exemplo n.º 7
0
 public Typ GetTypesById(int id)
 {
     return(Typs.Where(i => i.TypId == id).FirstOrDefault());
 }
Exemplo n.º 8
0
 static PersonIdToken TryParse(Pullenti.Ner.Token t, PersonIdToken prev)
 {
     if (t.IsValue("СВИДЕТЕЛЬСТВО", null))
     {
         Pullenti.Ner.Token tt1 = t;
         bool ip  = false;
         bool reg = false;
         for (Pullenti.Ner.Token tt = t.Next; tt != null; tt = tt.Next)
         {
             if (tt.IsCommaAnd || tt.Morph.Class.IsPreposition)
             {
                 continue;
             }
             if (tt.IsValue("РЕГИСТРАЦИЯ", null) || tt.IsValue("РЕЕСТР", null) || tt.IsValue("ЗАРЕГИСТРИРОВАТЬ", null))
             {
                 reg = true;
                 tt1 = tt;
             }
             else if (tt.IsValue("ИНДИВИДУАЛЬНЫЙ", null) || tt.IsValue("ИП", null))
             {
                 ip  = true;
                 tt1 = tt;
             }
             else if ((tt.IsValue("ВНЕСЕНИЕ", null) || tt.IsValue("ГОСУДАРСТВЕННЫЙ", null) || tt.IsValue("ЕДИНЫЙ", null)) || tt.IsValue("ЗАПИСЬ", null) || tt.IsValue("ПРЕДПРИНИМАТЕЛЬ", null))
             {
                 tt1 = tt;
             }
             else if (tt.GetReferent() != null && tt.GetReferent().TypeName == "DATERANGE")
             {
                 tt1 = tt;
             }
             else
             {
                 break;
             }
         }
         if (reg && ip)
         {
             return new PersonIdToken(t, tt1)
                    {
                        Typ = Typs.Keyword, Value = "СВИДЕТЕЛЬСТВО О ГОСУДАРСТВЕННОЙ РЕГИСТРАЦИИ ФИЗИЧЕСКОГО ЛИЦА В КАЧЕСТВЕ ИНДИВИДУАЛЬНОГО ПРЕДПРИНИМАТЕЛЯ"
                    }
         }
         ;
     }
     Pullenti.Ner.Core.TerminToken tok = m_Ontology.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No);
     if (tok != null)
     {
         Typs          ty  = (Typs)tok.Termin.Tag;
         PersonIdToken res = new PersonIdToken(tok.BeginToken, tok.EndToken)
         {
             Typ = ty, Value = tok.Termin.CanonicText
         };
         if (prev == null)
         {
             if (ty != Typs.Keyword)
             {
                 return(null);
             }
             for (t = tok.EndToken.Next; t != null; t = t.Next)
             {
                 Pullenti.Ner.Referent r = t.GetReferent();
                 if (r != null && (r is Pullenti.Ner.Geo.GeoReferent))
                 {
                     res.Referent = r;
                     res.EndToken = t;
                     continue;
                 }
                 if (t.IsValue("ГРАЖДАНИН", null) && t.Next != null && (t.Next.GetReferent() is Pullenti.Ner.Geo.GeoReferent))
                 {
                     res.Referent = t.Next.GetReferent();
                     t            = (res.EndToken = t.Next);
                     continue;
                 }
                 if (r != null)
                 {
                     break;
                 }
                 PersonAttrToken ait = PersonAttrToken.TryAttach(t, null, PersonAttrToken.PersonAttrAttachAttrs.No);
                 if (ait != null)
                 {
                     if (ait.Referent != null)
                     {
                         foreach (Pullenti.Ner.Slot s in ait.Referent.Slots)
                         {
                             if (s.TypeName == Pullenti.Ner.Person.PersonPropertyReferent.ATTR_REF && (s.Value is Pullenti.Ner.Geo.GeoReferent))
                             {
                                 res.Referent = s.Value as Pullenti.Ner.Referent;
                             }
                         }
                     }
                     res.EndToken = ait.EndToken;
                     break;
                 }
                 if (t.IsValue("ДАННЫЙ", null))
                 {
                     res.EndToken = t;
                     continue;
                 }
                 break;
             }
             if ((res.Referent is Pullenti.Ner.Geo.GeoReferent) && !(res.Referent as Pullenti.Ner.Geo.GeoReferent).IsState)
             {
                 res.Referent = null;
             }
             return(res);
         }
         if (ty == Typs.Number)
         {
             StringBuilder      tmp = new StringBuilder();
             Pullenti.Ner.Token tt  = tok.EndToken.Next;
             if (tt != null && tt.IsChar(':'))
             {
                 tt = tt.Next;
             }
             for (; tt != null; tt = tt.Next)
             {
                 if (tt.IsNewlineBefore)
                 {
                     break;
                 }
                 if (!(tt is Pullenti.Ner.NumberToken))
                 {
                     break;
                 }
                 tmp.Append(tt.GetSourceText());
                 res.EndToken = tt;
             }
             if (tmp.Length < 1)
             {
                 return(null);
             }
             res.Value     = tmp.ToString();
             res.HasPrefix = true;
             return(res);
         }
         if (ty == Typs.Seria)
         {
             StringBuilder      tmp = new StringBuilder();
             Pullenti.Ner.Token tt  = tok.EndToken.Next;
             if (tt != null && tt.IsChar(':'))
             {
                 tt = tt.Next;
             }
             bool nextNum = false;
             for (; tt != null; tt = tt.Next)
             {
                 if (tt.IsNewlineBefore)
                 {
                     break;
                 }
                 if (Pullenti.Ner.Core.MiscHelper.CheckNumberPrefix(tt) != null)
                 {
                     nextNum = true;
                     break;
                 }
                 if (!(tt is Pullenti.Ner.NumberToken))
                 {
                     if (!(tt is Pullenti.Ner.TextToken))
                     {
                         break;
                     }
                     if (!tt.Chars.IsAllUpper)
                     {
                         break;
                     }
                     Pullenti.Ner.NumberToken nu = Pullenti.Ner.Core.NumberHelper.TryParseRoman(tt);
                     if (nu != null)
                     {
                         tmp.Append(nu.GetSourceText());
                         tt = nu.EndToken;
                     }
                     else if (tt.LengthChar != 2)
                     {
                         break;
                     }
                     else
                     {
                         tmp.Append((tt as Pullenti.Ner.TextToken).Term);
                         res.EndToken = tt;
                     }
                     if (tt.Next != null && tt.Next.IsHiphen)
                     {
                         tt = tt.Next;
                     }
                     continue;
                 }
                 if (tmp.Length >= 4)
                 {
                     break;
                 }
                 tmp.Append(tt.GetSourceText());
                 res.EndToken = tt;
             }
             if (tmp.Length < 4)
             {
                 if (tmp.Length < 2)
                 {
                     return(null);
                 }
                 Pullenti.Ner.Token tt1 = res.EndToken.Next;
                 if (tt1 != null && tt1.IsComma)
                 {
                     tt1 = tt1.Next;
                 }
                 PersonIdToken next = TryParse(tt1, res);
                 if (next != null && next.Typ == Typs.Number)
                 {
                 }
                 else
                 {
                     return(null);
                 }
             }
             res.Value     = tmp.ToString();
             res.HasPrefix = true;
             return(res);
         }
         if (ty == Typs.Code)
         {
             for (Pullenti.Ner.Token tt = res.EndToken.Next; tt != null; tt = tt.Next)
             {
                 if (tt.IsCharOf(":") || tt.IsHiphen)
                 {
                     continue;
                 }
                 if (tt is Pullenti.Ner.NumberToken)
                 {
                     res.EndToken = tt;
                     continue;
                 }
                 break;
             }
         }
         if (ty == Typs.Address)
         {
             if (t.GetReferent() is Pullenti.Ner.Address.AddressReferent)
             {
                 res.Referent = t.GetReferent();
                 res.EndToken = t;
                 return(res);
             }
             for (Pullenti.Ner.Token tt = res.EndToken.Next; tt != null; tt = tt.Next)
             {
                 if (tt.IsCharOf(":") || tt.IsHiphen || tt.Morph.Class.IsPreposition)
                 {
                     continue;
                 }
                 if (tt.GetReferent() is Pullenti.Ner.Address.AddressReferent)
                 {
                     res.Referent = tt.GetReferent();
                     res.EndToken = tt;
                 }
                 break;
             }
             if (res.Referent == null)
             {
                 return(null);
             }
         }
         return(res);
     }
     else if (prev == null)
     {
         return(null);
     }
     Pullenti.Ner.Token t0 = t;
     Pullenti.Ner.Token t1 = Pullenti.Ner.Core.MiscHelper.CheckNumberPrefix(t0);
     if (t1 != null)
     {
         t = t1;
     }
     if (t is Pullenti.Ner.NumberToken)
     {
         StringBuilder tmp = new StringBuilder();
         PersonIdToken res = new PersonIdToken(t0, t)
         {
             Typ = Typs.Number
         };
         for (Pullenti.Ner.Token tt = t; tt != null; tt = tt.Next)
         {
             if (tt.IsNewlineBefore || !(tt is Pullenti.Ner.NumberToken))
             {
                 break;
             }
             tmp.Append(tt.GetSourceText());
             res.EndToken = tt;
         }
         if (tmp.Length < 4)
         {
             if (tmp.Length < 2)
             {
                 return(null);
             }
             if (prev == null || prev.Typ != Typs.Keyword)
             {
                 return(null);
             }
             PersonIdToken ne = TryParse(res.EndToken.Next, prev);
             if (ne != null && ne.Typ == Typs.Number)
             {
                 res.Typ = Typs.Seria;
             }
             else
             {
                 return(null);
             }
         }
         res.Value = tmp.ToString();
         if (t0 != t)
         {
             res.HasPrefix = true;
         }
         return(res);
     }
     if (t is Pullenti.Ner.ReferentToken)
     {
         Pullenti.Ner.Referent r = t.GetReferent();
         if (r != null)
         {
             if (r.TypeName == "DATE")
             {
                 return new PersonIdToken(t, t)
                        {
                            Typ = Typs.Date, Referent = r
                        }
             }
             ;
             if (r.TypeName == "ORGANIZATION")
             {
                 return new PersonIdToken(t, t)
                        {
                            Typ = Typs.Org, Referent = r
                        }
             }
             ;
             if (r.TypeName == "ADDRESS")
             {
                 return new PersonIdToken(t, t)
                        {
                            Typ = Typs.Address, Referent = r
                        }
             }
             ;
         }
     }
     if ((prev != null && prev.Typ == Typs.Keyword && (t is Pullenti.Ner.TextToken)) && !t.Chars.IsAllLower && t.Chars.IsLetter)
     {
         PersonIdToken rr = TryParse(t.Next, prev);
         if (rr != null && rr.Typ == Typs.Number)
         {
             return new PersonIdToken(t, t)
                    {
                        Typ = Typs.Seria, Value = (t as Pullenti.Ner.TextToken).Term
                    }
         }
         ;
     }
     if ((t != null && t.IsValue("ОТ", "ВІД") && (t.Next is Pullenti.Ner.ReferentToken)) && t.Next.GetReferent().TypeName == "DATE")
     {
         return new PersonIdToken(t, t.Next)
                {
                    Typ = Typs.Date, Referent = t.Next.GetReferent()
                }
     }
     ;
     return(null);
 }