/// <summary>
        /// Method used to filter facts from (phrase) triples.
        /// </summary>
        /// <param name="triples">List of (phrase) triples.</param>
        /// <param name="patternTriples">List of pattern triples.</param>
        /// <param name="lexicalizations">List of lexicalizations collections.</param>
        /// <returns>These (phrase) triples which match to collection of pattern triples.</returns>
        public static List<Triple> filter(List<Triple> triples, List<Triple> patternTriples, List<LexCollection> lexicalizations, EntityType typeHierarchy)
        {
            List<Triple> result = new List<Triple>();

            foreach (Triple t in triples) {

                foreach (Triple pt in patternTriples) {

                    foreach (LexCollection l in lexicalizations) {

                        // if property name of pattern triple and lexicalizations collection name are the same
                        if (pt.property.type.name.Equals(l.name, StringComparison.OrdinalIgnoreCase)) {

                            foreach (String lex in l.items) {
                                // if lexicalization is equal to triple property
                                if (lex.Equals(t.property.value, StringComparison.OrdinalIgnoreCase)) {
                                    // create new triple - combination of (phrase) triple (names) and pattern triple (types)
                                    Triple toAdd = new Triple();
                                    toAdd.@object = new Entity([email protected], typeHierarchy.getType([email protected]()));
                                    toAdd.property = new Entity(t.property.value, pt.property.type);
                                    toAdd.subject = new Entity(t.subject.value, typeHierarchy.getType(t.subject.ToString()));

                                    // add to result list and jump out from loop
                                    result.Add(toAdd);
                                    goto outer;
                                }
                            }
                        }
                    }
                }
                outer: {}
            }
            return result;
        }
Ejemplo n.º 2
0
 private String subtypesToString(EntityType types, int level)
 {
     StringBuilder result = new StringBuilder();
     for (int i = 1; i < level; ++i) {
         result.Append("|   ");
     }
     if (level > 0) result.Append("|-");
     result.Append(types.name);
     result.Append("\n");
     foreach (EntityType et in types.subtypes) {
         result.Append(subtypesToString(et, level + 1));
     }
     return result.ToString();
 }
Ejemplo n.º 3
0
 private static EntityType search(EntityType type, String typeToFind)
 {
     if (type.name.Equals(typeToFind, StringComparison.OrdinalIgnoreCase)) {
         return type;
     }
     EntityType result = null;
     EntityType secondResult = null;
     foreach (EntityType et in type.subtypes) {
         if (result == null)
             result = search(et, typeToFind);
         else if (secondResult == null)
             secondResult = search(et, typeToFind);
         else
             return type;
     }
     if (secondResult != null)
         return type;
     if (result != null)
         if (type.subtypes.Contains(result) && result.name.Equals(typeToFind, StringComparison.OrdinalIgnoreCase))
             return type;
     return result;
 }
Ejemplo n.º 4
0
        private void buttonLoadTypes_Click(object sender, EventArgs e)
        {
            openFileDialog.FileName = "[name]_type_hierarchy.json";

            if (openFileDialog.ShowDialog() == DialogResult.OK) {
                types = input.readTypeHierarchy(openFileDialog.FileName);
                listBoxTypeHierarchy.Items.Clear();
                foreach (String s in types.getHierarchyString().Split('\n')) {
                    listBoxTypeHierarchy.Items.Add(s);
                }
                //listBoxTypeHierarchy.Items.Add(types.getType("Opel"));
                //listBoxTypeHierarchy.Items.Add(types.getType("Daewoo"));
                //listBoxTypeHierarchy.Items.Add(types.getType("Nothing"));

            }
        }