001package org.clafer.ontology;
002
003import java.util.ArrayList;
004import java.util.List;
005
006/**
007 * Knowledge database containing facts of is-a and has-a relationships.
008 *
009 * @author jimmy
010 */
011public class KnowledgeDatabase extends ConstraintDatabase {
012
013    private final Relation<Concept> isA = new Relation<>();
014    private final Relation<Concept> hasA = new Relation<>();
015    private final List<ConstraintDatabase[]> disjunctions = new ArrayList<>();
016
017    public Concept newConcept(String name) {
018        Concept concept = new Concept(name);
019        newIsA(concept, concept);
020        return concept;
021    }
022
023    public void newIsA(Concept sub, Concept sup) {
024        isA.add(sub, sup);
025    }
026
027    public void newHasA(Concept parent, Concept child) {
028        hasA.add(parent, child);
029    }
030
031    public void newDisjunction(ConstraintDatabase... disjunction) {
032        if (disjunction.length <= 1) {
033            throw new IllegalArgumentException();
034        }
035        this.disjunctions.add(disjunction);
036    }
037
038    public static ConstraintDatabase or() {
039        return new ConstraintDatabase();
040    }
041
042    public Oracle oracle() {
043        return new Oracle(isA, hasA, this, disjunctions);
044    }
045}