aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/rules/clauses/Clause.java
blob: 2adb66bbc679e0844390de43fa112575b065cdfe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package uk.ac.ox.cs.pagoda.rules.clauses;

public class Clause {

//    public static final String IF = ":-";
//    public static final String OR = "|";
//    public static final String AND = ",";
//
//    protected final List<List<Atom>> head;
//    protected final List<Atom> body;
//
//    protected Clause(Atom[] headAtoms, Atom[] bodyAtoms) {
//        this.head = Collections.singletonList(Arrays.asList(headAtoms));
//        this.body= Arrays.asList(bodyAtoms);
//    }
//
//    protected Clause(String s) {
//        this.headAtoms = null;
//        this.bodyAtoms = null;
//    }
//
//    public int getHeadLength() {
//        return headAtoms.length;
//    }
//
//    public Atom getHeadAtom(int atomIndex) {
//        return headAtoms[atomIndex];
//    }
//
//    public Atom[] getHeadAtoms() {
//        return headAtoms.clone();
//    }
//
//    public int getBodyLength() {
//        return bodyAtoms.length;
//    }
//
//    public Atom getBodyAtom(int atomIndex) {
//        return bodyAtoms[atomIndex];
//    }
//
//    public Atom[] getBodyAtoms() {
//        return bodyAtoms.clone();
//    }
//
//    public String toString(Prefixes prefixes) {
//        StringBuilder buffer = new StringBuilder();
//        for(int headIndex = 0; headIndex < headAtoms.length; headIndex++) {
//            if(headIndex != 0)
//                buffer.append(" ").append(OR).append(" ");
//            buffer.append(headAtoms[headIndex].toString(prefixes));
//        }
//        buffer.append(" ").append(IF).append(" ");
//        for(int bodyIndex = 0; bodyIndex < bodyAtoms.length; bodyIndex++) {
//            if(bodyIndex != 0)
//                buffer.append(AND).append(" ");
//            buffer.append(bodyAtoms[bodyIndex].toString(prefixes));
//        }
//        return buffer.toString();
//    }
//
//    public String toString() {
//        return toString(Prefixes.STANDARD_PREFIXES);
//    }
//
//    protected static InterningManager<? extends Clause> s_interningManager = new InterningManager<Clause>() {
//        protected boolean equal(Clause object1, Clause object2) {
//            if(object1.head.length != object2.headAtoms.length
//                    || object1.bodyAtoms.length != object2.bodyAtoms.length)
//                return false;
//            for(int index = object1.headAtoms.length - 1; index >= 0; --index)
//                if(object1.headAtoms[index] != object2.headAtoms[index])
//                    return false;
//            for(int index = object1.bodyAtoms.length - 1; index >= 0; --index)
//                if(object1.bodyAtoms[index] != object2.bodyAtoms[index])
//                    return false;
//            return true;
//        }
//
//        protected int getHashCode(Clause object) {
//            int hashCode = 0;
//            for(int index = object.bodyAtoms.length - 1; index >= 0; --index)
//                hashCode += object.bodyAtoms[index].hashCode();
//            for(int index = object.headAtoms.length - 1; index >= 0; --index)
//                hashCode += object.headAtoms[index].hashCode();
//            return hashCode;
//        }
//    };
//
//    /**
//     * Creates a clause from a string.
//     *
//     * @param s
//     * @return
//     */
//    public static Clause create(String s) {
//        return s_interningManager.intern(new Clause(s));
//    }

}