public void Sort_simple()
        {
            var entityTypeA = new NamedEntityType(typeof(A));

            entityTypeA.GetOrSetPrimaryKey(entityTypeA.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var entityTypeB = new NamedEntityType(typeof(B));

            entityTypeB.GetOrSetPrimaryKey(entityTypeB.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var entityTypeC = new NamedEntityType(typeof(C));

            entityTypeC.GetOrSetPrimaryKey(entityTypeC.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            // B -> A -> C
            entityTypeC.GetOrAddForeignKey(entityTypeA.GetPrimaryKey(), entityTypeC.GetOrAddProperty("P", typeof(int)));
            entityTypeA.GetOrAddForeignKey(entityTypeB.GetPrimaryKey(), entityTypeA.GetOrAddProperty("P", typeof(int)));

            var model = new EntityTypeGraph();

            model.Populate(entityTypeA, entityTypeB, entityTypeC);

            Assert.Equal(
                new[] { entityTypeB.Name, entityTypeA.Name, entityTypeC.Name },
                model.TopologicalSort().SelectMany(e => e).Select(e => e.Name).ToArray());
        }
コード例 #2
0
        public void Sort_leafy_cycle()
        {
            var entityTypeA = new NamedEntityType(typeof(A));

            entityTypeA.SetKey(entityTypeA.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            var entityTypeB = new NamedEntityType(typeof(B));

            entityTypeB.SetKey(entityTypeB.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            var entityTypeC = new NamedEntityType(typeof(C));

            entityTypeC.SetKey(entityTypeC.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            // C -> B -> C -> A
            entityTypeB.AddForeignKey(entityTypeC.GetKey(), entityTypeB.AddProperty("P", typeof(int)));
            entityTypeC.AddForeignKey(entityTypeB.GetKey(), entityTypeC.AddProperty("P", typeof(int)));
            entityTypeA.AddForeignKey(entityTypeC.GetKey(), entityTypeA.AddProperty("P", typeof(int)));

            var model = new EntityTypeGraph();

            model.Populate(entityTypeA, entityTypeB, entityTypeC);

            Assert.Equal(
                Strings.FormatCircularDependency("C -> B -> C -> A"),
                Assert.Throws <InvalidOperationException>(() => model.TopologicalSort()).Message);
        }
コード例 #3
0
        public void Sort_reverse()
        {
            var entityTypeA = new NamedEntityType(typeof(A));

            entityTypeA.SetKey(entityTypeA.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            var entityTypeB = new NamedEntityType(typeof(B));

            entityTypeB.SetKey(entityTypeB.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            var entityTypeC = new NamedEntityType(typeof(C));

            entityTypeC.SetKey(entityTypeC.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            // C -> B -> A
            entityTypeA.AddForeignKey(entityTypeB.GetKey(), entityTypeA.AddProperty("P", typeof(int)));
            entityTypeB.AddForeignKey(entityTypeC.GetKey(), entityTypeB.AddProperty("P", typeof(int)));

            var model = new EntityTypeGraph();

            model.Populate(entityTypeA, entityTypeB, entityTypeC);

            Assert.Equal(
                new[] { entityTypeC.Name, entityTypeB.Name, entityTypeA.Name },
                model.TopologicalSort().SelectMany(e => e).Select(e => e.Name).ToArray());
        }
        public void Sort_circular_transitive()
        {
            var entityTypeA = new NamedEntityType(typeof(A));

            entityTypeA.GetOrSetPrimaryKey(entityTypeA.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var entityTypeB = new NamedEntityType(typeof(B));

            entityTypeB.GetOrSetPrimaryKey(entityTypeB.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            var entityTypeC = new NamedEntityType(typeof(C));

            entityTypeC.GetOrSetPrimaryKey(entityTypeC.GetOrAddProperty("Id", typeof(int), shadowProperty: true));

            // A -> C -> B -> A
            entityTypeA.GetOrAddForeignKey(entityTypeB.GetPrimaryKey(), entityTypeA.GetOrAddProperty("P", typeof(int)));
            entityTypeB.GetOrAddForeignKey(entityTypeC.GetPrimaryKey(), entityTypeB.GetOrAddProperty("P", typeof(int)));
            entityTypeC.GetOrAddForeignKey(entityTypeA.GetPrimaryKey(), entityTypeC.GetOrAddProperty("P", typeof(int)));

            var model = new EntityTypeGraph();

            model.Populate(entityTypeA, entityTypeB, entityTypeC);

            Assert.Equal(
                Strings.FormatCircularDependency(typeof(A).FullName + " -> " + typeof(C).FullName + " -> " + typeof(B).FullName + " -> " + typeof(A).FullName),
                Assert.Throws <InvalidOperationException>(() => model.TopologicalSort()).Message);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: xpolakm5/wikipedia
        private static string[] GetNamedEntities(KnowlegeData item, NamedEntityType type)
        {
            var items = new List <string>();

            foreach (var value in item.Items.Where(x => x.Key.Type == type).Select(l => l.Value))
            {
                items.AddRange(value.Where(x => x.Length > 1));
            }

            return(items.ToArray());
        }
コード例 #6
0
        public void Sort_preserves_graph()
        {
            var entityTypeA = new NamedEntityType(typeof(A));

            entityTypeA.SetKey(entityTypeA.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            var entityTypeB = new NamedEntityType(typeof(B));

            entityTypeB.SetKey(entityTypeB.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            var entityTypeC = new NamedEntityType(typeof(C));

            entityTypeC.SetKey(entityTypeC.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            // B -> A -> C
            entityTypeC.AddForeignKey(entityTypeA.GetKey(), entityTypeC.AddProperty("P", typeof(int)));
            entityTypeA.AddForeignKey(entityTypeB.GetKey(), entityTypeA.AddProperty("P", typeof(int)));

            var model = new EntityTypeGraph();

            model.Populate(entityTypeA, entityTypeB, entityTypeC);

            Assert.Equal(
                new[] { entityTypeB.Name, entityTypeA.Name, entityTypeC.Name },
                model.TopologicalSort().SelectMany(e => e).Select(e => e.Name).ToArray());

            Assert.Equal(
                new[] { entityTypeA, entityTypeB, entityTypeC },
                model.Vertices);

            Assert.Equal(
                new[] { entityTypeC },
                model.GetOutgoingNeighbours(entityTypeA));

            Assert.Equal(
                new[] { entityTypeA },
                model.GetOutgoingNeighbours(entityTypeB));

            Assert.Equal(
                new[] { entityTypeB.Name, entityTypeA.Name, entityTypeC.Name },
                model.TopologicalSort().SelectMany(e => e).Select(e => e.Name).ToArray());
        }
        /**
         * <summary>Static function to convert a {@link NamedEntityType} to string form.</summary>
         * <param name="entityType">Entity type in {@link NamedEntityType} form</param>
         * <returns>Entity type in string form</returns>
         */
        public static string GetNamedEntityType(NamedEntityType entityType)
        {
            switch (entityType)
            {
            case NamedEntityType.PERSON:
                return("PERSON");

            case NamedEntityType.LOCATION:
                return("LOCATION");

            case NamedEntityType.ORGANIZATION:
                return("ORGANIZATION");

            case NamedEntityType.TIME:
                return("TIME");

            case NamedEntityType.MONEY:
                return("MONEY");

            default:
                return("NONE");
            }
        }
コード例 #8
0
        public void Sort_no_edges()
        {
            var entityTypeA = new NamedEntityType(typeof(A));

            entityTypeA.SetKey(entityTypeA.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            var entityTypeB = new NamedEntityType(typeof(B));

            entityTypeB.SetKey(entityTypeB.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            var entityTypeC = new NamedEntityType(typeof(C));

            entityTypeC.SetKey(entityTypeC.AddProperty("Id", typeof(int), shadowProperty: true, concurrencyToken: false));

            // A B C
            var model = new EntityTypeGraph();

            model.Populate(entityTypeC, entityTypeA, entityTypeB);

            Assert.Equal(
                new[] { entityTypeC.Name, entityTypeA.Name, entityTypeB.Name, },
                model.TopologicalSort().SelectMany(e => e).Select(e => e.Name).ToArray());
        }
コード例 #9
0
 public static NamedEntity CreateNamedEntity(NamedEntityType net, int? initial = null) {
     return CreateNamedEntity(net, null, initial);
 }
コード例 #10
0
 public static NamedEntity CreateNamedEntity(NamedEntityType net, NamedEntity existing) {
     return CreateNamedEntity(net, existing, null);
 }
コード例 #11
0
 public static Company CreateCompany(NamedEntityType net) {
     var c = new Company();
     CreateNamedEntity(net, c);
     c.CompanyNo = "CompanyNo_" + _random.Next(1, 100);
     c.CompanyType = (CompanyType) _random.Next(1, 3);
     c.Address = CreateAddress();
     return c;
 }
コード例 #12
0
 public static Company CreateLongNoCompany(NamedEntityType net) {
     var c = CreateCompany(net);
     c.CompanyNo += "_long";
     return c;
 }
コード例 #13
0
 public static NamedEntity CreateNamedEntity(NamedEntityType net, NamedEntity existing, int? initial) {
     var ne = existing ?? new NamedEntity();
     ne.Id = Guid.NewGuid();
     ne.UserNameCreate = "Tester_" + _random.Next(3, 10);
     ne.TimeCreate = DateTime.UtcNow;
     ne.IsCanceled = _random.Next(0, 1) != 0;
     ne.Description = "Description_" + _random.Next(3, 100);
     ne.Name = "Name_" + (initial.HasValue ? initial :_random.Next(3, 100));
     ne.NamedEntityType = net;
     return ne;
 }
コード例 #14
0
 /**
  * <summary>A constructor of {@link NamedEntityWord} which takes name and nameEntityType as input and sets the corresponding attributes</summary>
  * <param name="name">Name of the word</param>
  * <param name="namedEntityType">{@link NamedEntityType} of the word</param>
  */
 public NamedEntityWord(string name, NamedEntityType namedEntityType) : base(name)
 {
     this._namedEntityType = namedEntityType;
 }
        /**
         * <summary>Another constructor of {@link NamedEntitySentence}. It takes input a named entity annotated sentence in string
         * form, divides the sentence with respect to space and sets the tagged words with respect to their tags.</summary>
         * <param name="sentence">Named Entity annotated sentence in string form</param>
         */
        public NamedEntitySentence(string sentence)
        {
            NamedEntityType type = NamedEntityType.NONE;

            words = new List <Word>();
            string[] wordArray = sentence.Split(" ");
            foreach (var word in wordArray)
            {
                if (word != "")
                {
                    if (word != "<b_enamex")
                    {
                        string candidate;
                        if (word.StartsWith("TYPE=\""))
                        {
                            int typeIndexEnd = word.IndexOf('\"', 6);
                            if (typeIndexEnd != -1)
                            {
                                string entityType = word.Substring(6, typeIndexEnd - 6);
                                type = NamedEntityTypeStatic.GetNamedEntityType(entityType);
                            }

                            if (word.EndsWith("e_enamex>"))
                            {
                                candidate = word.Substring(word.IndexOf('>') + 1,
                                                           word.IndexOf('<') - word.IndexOf('>') - 1);
                                if (candidate != "")
                                {
                                    words.Add(new NamedEntityWord(candidate, type));
                                }

                                type = NamedEntityType.NONE;
                            }
                            else
                            {
                                candidate = word.Substring(word.IndexOf('>') + 1);
                                if (candidate != "")
                                {
                                    words.Add(new NamedEntityWord(candidate, type));
                                }
                            }
                        }
                        else
                        {
                            if (word.EndsWith("e_enamex>"))
                            {
                                candidate = word.Substring(0, word.IndexOf('<'));
                                if (candidate != "")
                                {
                                    words.Add(new NamedEntityWord(candidate, type));
                                }

                                type = NamedEntityType.NONE;
                            }
                            else
                            {
                                if (word != "")
                                {
                                    words.Add(new NamedEntityWord(word, type));
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #16
0
ファイル: NamedEntity.cs プロジェクト: nemcek/notenizer
 public NamedEntity(String namedEntity)
 {
     _value = namedEntity == null ? String.Empty : namedEntity;
     _neType = Parse(namedEntity);
 }
コード例 #17
0
ファイル: RegexKeyType.cs プロジェクト: xpolakm5/wikipedia
 public RegexKeyType(string value, NamedEntityType type)
 {
     this.Value = value;
     this.Type  = type;
 }
コード例 #18
0
ファイル: Program.cs プロジェクト: irfiit/wikipedia
		private static string[] GetNamedEntities(KnowlegeData item, NamedEntityType type)
		{
			var items = new List<string>();
			foreach(var value in item.Items.Where(x => x.Key.Type == type).Select(l => l.Value))
			{
				items.AddRange(value.Where(x => x.Length > 1));
			}

			return items.ToArray();
		}
コード例 #19
0
ファイル: RegexKeyType.cs プロジェクト: irfiit/wikipedia
		public RegexKeyType(string value, NamedEntityType type)
		{
			this.Value = value;
			this.Type = type;
		}