Skip to content

Method: getValue()

1: package cz.cvut.kbss.jopa.query.soql;
2:
3: public class SoqlAttribute extends SoqlParameter {
4:
5: private String value;
6:
7: private boolean isNot = false;
8:
9: private String operator;
10:
11: private String prefix = "http://www.example.org/";
12:
13: private String rdfType = "a";
14:
15: private boolean isOrderBy = false;
16:
17: private boolean isGroupBy = false;
18:
19: public SoqlAttribute() {
20: super();
21: }
22:
23: public String getValue() {
24: return value;
25: }
26:
27: public void setValue(String value) {
28: this.value = value;
29: }
30:
31: public boolean isNot() {
32: return isNot;
33: }
34:
35: public void setNot(boolean not) {
36: isNot = not;
37: }
38:
39: public void setOperator(String operator) {
40: this.operator = operator;
41: }
42:
43: public String getOperator() {
44: return operator;
45: }
46:
47: public void setPrefix(String prefix) {
48: this.prefix = prefix;
49: }
50:
51: public String getPrefix() {
52: return this.prefix;
53: }
54:
55: public void setRdfType(String rdfType) {
56: this.rdfType = rdfType;
57: }
58:
59: public String getRdfType() {
60: return this.rdfType;
61: }
62:
63: public boolean isOrderBy() {
64: return isOrderBy;
65: }
66:
67: public void setOrderBy(boolean orderBy) {
68: isOrderBy = orderBy;
69: }
70:
71: public boolean isGroupBy() {
72: return isGroupBy;
73: }
74:
75: public void setGroupBy(boolean groupBy) {
76: isGroupBy = groupBy;
77: }
78:
79: public boolean isFilter() {
80: return !operator.isEmpty() && !"=".equals(operator);
81: }
82:
83: public boolean isObject() {
84: return !getFirstNode().hasNextChild();
85: }
86:
87: private boolean isValueParam() {
88: return !operator.isEmpty() && value.charAt(0) == ':';
89: }
90:
91: public String getFilter() {
92: StringBuilder buildFilter = new StringBuilder();
93: if ("LIKE".equals(operator)) {
94: buildFilter.append("regex(").append(getAsParam()).append(", ?").append(value.substring(1))
95: .append(") ");
96: } else {
97: buildFilter.append(getAsParam()).append(" ").append(this.operator).append(" ").append("?")
98: .append(value.substring(1));
99: }
100: return buildFilter.toString();
101: }
102:
103: public String getTriplePattern() {
104: StringBuilder buildTP = new StringBuilder("?x ");
105: if (isObject()) {
106: buildTP.append(getRdfType()).append(" ")
107: .append(toIri(getFirstNode())).append(" . ");
108: } else {
109: SoqlNode pointer = getFirstNode().getChild();
110: StringBuilder buildParam = new StringBuilder("?");
111: buildParam.append(getFirstNode().getValue());
112: buildParam.append(pointer.getCapitalizedValue());
113: String param;
114: if (pointer.hasNextChild()) {
115: param = "?" + pointer.getValue();
116: } else {
117: if (isFilter()) {
118: param = buildParam.toString();
119: } else {
120: param = "?" + value.substring(1);
121: }
122: }
123: buildTP.append(toIri(pointer)).append(" ").append(param).append(" . ");
124: while (pointer.hasNextChild()) {
125: SoqlNode newPointer = pointer.getChild();
126: buildTP.append("?").append(pointer.getValue())
127: .append(" ").append(toIri(newPointer)).append(" ");
128: buildParam.append(newPointer.getCapitalizedValue());
129: if (newPointer.hasNextChild()) {
130: buildTP.append("?").append(pointer.getChild().getValue());
131: } else {
132: if (isFilter()) {
133: buildTP.append(buildParam);
134: } else {
135: buildTP.append("?").append(value.substring(1));
136: }
137: }
138: buildTP.append(" . ");
139: pointer = newPointer;
140: }
141: }
142: return buildTP.toString();
143: }
144:
145: private StringBuilder toIri(SoqlNode node) {
146: StringBuilder sb = new StringBuilder("<");
147: String prefix = node.getIri().isEmpty() ? getPrefix() + node.getValue() : node.getIri();
148: sb.append(prefix).append(">");
149: return sb;
150: }
151: }