diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-07 19:26:24 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-07 19:26:24 +0100 |
| commit | 5be5fd3daa0d50980fb3791e904e035cdbca254f (patch) | |
| tree | 8109fdd92d6a8f3b59b47f147d21e23b84301494 /src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java | |
| parent | 11a432bfc3cb11e07c68c4298fcec060ff1e25fa (diff) | |
| download | ACQuA-5be5fd3daa0d50980fb3791e904e035cdbca254f.tar.gz ACQuA-5be5fd3daa0d50980fb3791e904e035cdbca254f.zip | |
Making the output machine-readable (JSON).
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java index 8d7e0b1..183cbe1 100644 --- a/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java +++ b/src/uk/ac/ox/cs/pagoda/query/AnswerTuple.java | |||
| @@ -1,13 +1,10 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | 1 | package uk.ac.ox.cs.pagoda.query; |
| 2 | 2 | ||
| 3 | import java.util.HashMap; | 3 | import com.google.gson.*; |
| 4 | import java.util.Map; | ||
| 5 | |||
| 6 | import org.semanticweb.HermiT.model.Constant; | 4 | import org.semanticweb.HermiT.model.Constant; |
| 7 | import org.semanticweb.HermiT.model.Individual; | 5 | import org.semanticweb.HermiT.model.Individual; |
| 8 | import org.semanticweb.HermiT.model.Term; | 6 | import org.semanticweb.HermiT.model.Term; |
| 9 | import org.semanticweb.HermiT.model.Variable; | 7 | import org.semanticweb.HermiT.model.Variable; |
| 10 | |||
| 11 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 8 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 12 | import uk.ac.ox.cs.JRDFox.model.Datatype; | 9 | import uk.ac.ox.cs.JRDFox.model.Datatype; |
| 13 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; | 10 | import uk.ac.ox.cs.JRDFox.model.GroundTerm; |
| @@ -15,6 +12,10 @@ import uk.ac.ox.cs.JRDFox.model.Literal; | |||
| 15 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | 12 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; |
| 16 | import uk.ac.ox.cs.pagoda.util.Namespace; | 13 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 17 | 14 | ||
| 15 | import java.lang.reflect.Type; | ||
| 16 | import java.util.HashMap; | ||
| 17 | import java.util.Map; | ||
| 18 | |||
| 18 | public class AnswerTuple { | 19 | public class AnswerTuple { |
| 19 | 20 | ||
| 20 | public static final String SEPARATOR = "\t"; | 21 | public static final String SEPARATOR = "\t"; |
| @@ -40,17 +41,21 @@ public class AnswerTuple { | |||
| 40 | m_tuple = new GroundTerm[arity]; | 41 | m_tuple = new GroundTerm[arity]; |
| 41 | for (int i = 0; i < arity; ++i) m_tuple[i] = sup.m_tuple[i]; | 42 | for (int i = 0; i < arity; ++i) m_tuple[i] = sup.m_tuple[i]; |
| 42 | } | 43 | } |
| 44 | |||
| 45 | private AnswerTuple(String m_str) { | ||
| 46 | this.m_str = m_str; | ||
| 47 | } | ||
| 43 | 48 | ||
| 44 | public int getArity() { | 49 | public int getArity() { |
| 45 | return m_tuple.length; | 50 | return m_tuple.length; |
| 46 | } | 51 | } |
| 47 | 52 | ||
| 48 | public int hashCode() { | 53 | public int hashCode() { |
| 49 | // return toString().hashCode(); | 54 | return toString().hashCode(); |
| 50 | int code = 0; | 55 | // int code = 0; |
| 51 | for (int i = 0; i < m_tuple.length; ++i) | 56 | // for (int i = 0; i < m_tuple.length; ++i) |
| 52 | code = code * 1997 + m_tuple[i].hashCode(); | 57 | // code = code * 1997 + m_tuple[i].hashCode(); |
| 53 | return code; | 58 | // return code; |
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | public boolean equals(Object obj) { | 61 | public boolean equals(Object obj) { |
| @@ -131,5 +136,21 @@ public class AnswerTuple { | |||
| 131 | if (length == extendedTuple.getArity()) return extendedTuple; | 136 | if (length == extendedTuple.getArity()) return extendedTuple; |
| 132 | else return new AnswerTuple(extendedTuple, length); | 137 | else return new AnswerTuple(extendedTuple, length); |
| 133 | } | 138 | } |
| 134 | 139 | ||
| 140 | |||
| 141 | public static class AnswerTupleSerializer implements JsonSerializer<AnswerTuple> { | ||
| 142 | |||
| 143 | public JsonElement serialize(AnswerTuple src, Type typeOfSrc, JsonSerializationContext context) { | ||
| 144 | return new JsonPrimitive(src.toString()); | ||
| 145 | } | ||
| 146 | |||
| 147 | } | ||
| 148 | |||
| 149 | public class AnswerTupleDeserializer implements JsonDeserializer<AnswerTuple> { | ||
| 150 | public AnswerTuple deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | ||
| 151 | throws JsonParseException { | ||
| 152 | return new AnswerTuple(json.getAsJsonPrimitive().getAsString()); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 135 | } | 156 | } |
