Skip to content

Package: SoqlAttribute

SoqlAttribute

nameinstructionbranchcomplexitylinemethod
SoqlAttribute(SoqlNode)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getBasicGraphPattern(String)
M: 1 C: 146
99%
M: 1 C: 17
94%
M: 1 C: 9
90%
M: 1 C: 31
97%
M: 0 C: 1
100%
getFilterExpressions()
M: 4 C: 40
91%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 0 C: 8
100%
M: 0 C: 1
100%
getOperator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValue()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isGroupBy()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isInstanceOf()
M: 0 C: 11
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isNot()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isObject()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isOrderBy()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isProjected()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
requiresFilter()
M: 0 C: 15
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setGroupBy(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setNot(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setOperator(FilterableExpression)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setOrderBy(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setProjected(boolean)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setValue(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toIri(SoqlNode)
M: 0 C: 12
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.query.soql;
19:
20: import cz.cvut.kbss.jopa.query.sparql.SparqlConstants;
21: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
22:
23: import java.util.Collections;
24: import java.util.List;
25:
26: public class SoqlAttribute extends SoqlParameter {
27:
28: private static final String TRIPLE_END = " . ";
29:
30: private String value;
31:
32: private boolean isNot = false;
33:
34: private FilterableExpression operator;
35:
36: private boolean isOrderBy = false;
37:
38: private boolean isGroupBy = false;
39:
40: private boolean projected;
41:
42: public SoqlAttribute(SoqlNode firstNode) {
43: super(firstNode);
44: }
45:
46: public String getValue() {
47: return value;
48: }
49:
50: public void setValue(String value) {
51: this.value = value;
52: }
53:
54: public boolean isNot() {
55: return isNot;
56: }
57:
58: public void setNot(boolean not) {
59: isNot = not;
60: }
61:
62: public void setOperator(FilterableExpression operator) {
63: this.operator = operator;
64: }
65:
66: public FilterableExpression getOperator() {
67: return operator;
68: }
69:
70: public boolean isOrderBy() {
71: return isOrderBy;
72: }
73:
74: public void setOrderBy(boolean orderBy) {
75: isOrderBy = orderBy;
76: }
77:
78: public boolean isGroupBy() {
79: return isGroupBy;
80: }
81:
82: public void setGroupBy(boolean groupBy) {
83: isGroupBy = groupBy;
84: }
85:
86: public boolean isProjected() {
87: return projected;
88: }
89:
90: public void setProjected(boolean projected) {
91: this.projected = projected;
92: }
93:
94: public boolean requiresFilter() {
95:• return (operator != null && operator.requiresFilterExpression()) || getFirstNode().requiresFilterExpression();
96: }
97:
98: public boolean isObject() {
99:• return !getFirstNode().hasChild();
100: }
101:
102: public boolean isInstanceOf() {
103:• return !getFirstNode().hasChild() && operator == null;
104: }
105:
106: public List<String> getFilterExpressions() {
107:• assert requiresFilter();
108: String filterParam = getAsParam();
109: final String filterValue = SoqlUtils.soqlVariableToSparqlVariable(value);
110:• if (getFirstNode().requiresFilterExpression()) {
111: filterParam = getFirstNode().toFilterExpression(filterParam, filterValue);
112: }
113:• if (operator != null && operator.requiresFilterExpression()) {
114: return Collections.singletonList(operator.toFilterExpression(filterParam, filterValue));
115: } else {
116: return Collections.singletonList(filterParam + " = " + filterValue);
117: }
118: }
119:
120: public String getBasicGraphPattern(String rootVariable) {
121: StringBuilder buildTP = new StringBuilder(rootVariable).append(' ');
122:• if (isInstanceOf()) {
123: buildTP.append(SoqlConstants.RDF_TYPE).append(' ')
124: .append(toIri(getFirstNode())).append(TRIPLE_END);
125: } else {
126:• if (isObject()) {
127: return "";
128: }
129: SoqlNode pointer = getFirstNode().getChild();
130: StringBuilder buildParam = new StringBuilder("?");
131: buildParam.append(getFirstNode().getValue());
132: buildParam.append(pointer.getCapitalizedValue());
133: String param;
134:• if (pointer.hasChild() || value == null) {
135: param = "?" + pointer.getValue();
136: } else {
137:• if (requiresFilter()) {
138: param = buildParam.toString();
139: } else {
140: param = SoqlUtils.soqlVariableToSparqlVariable(value);
141: }
142: }
143: buildTP.append(toIri(pointer)).append(' ').append(param).append(TRIPLE_END);
144:• while (pointer.hasChild()) {
145: SoqlNode newPointer = pointer.getChild();
146:• if (newPointer.getIri().isEmpty()) {
147: break;
148: }
149: buildTP.append('?').append(pointer.getValue())
150: .append(' ').append(toIri(newPointer)).append(' ');
151: buildParam.append(newPointer.getCapitalizedValue());
152:• if (newPointer.hasChild()) {
153: buildTP.append('?').append(pointer.getChild().getValue());
154: } else {
155:• if (requiresFilter()) {
156: buildTP.append(buildParam);
157: } else {
158: buildTP.append(SoqlUtils.soqlVariableToSparqlVariable(value));
159: }
160: }
161: buildTP.append(TRIPLE_END);
162: pointer = newPointer;
163: }
164: }
165: return buildTP.toString();
166: }
167:
168: private static String toIri(SoqlNode node) {
169: final String nodeIri = node.getIri();
170:• return SparqlConstants.RDF_TYPE_SHORTCUT.equals(nodeIri) ? nodeIri : IdentifierTransformer.stringifyIri(nodeIri);
171: }
172: }