- public static VariableMap standardPropertyDomainProperties = new VariableMapImpl() {
-
- VariableMap getValueVariableMap(ReadGraph graph, Variable context) throws DatabaseException {
- Resource represents = context.getPossibleRepresents(graph);
- if(represents == null) return null;
-
- VariableMap map = graph.isImmutable(represents) ?
- graph.syncRequest(new PropertyVariableMapRequest(represents), TransientCacheListener.<VariableMap>instance()) :
- (VariableMap)graph.getPossibleRelatedValue2(represents, Layer0.getInstance(graph).domainProperties, represents);
-
- if(map == standardPropertyDomainProperties) return null;
- else return map;
-
- }
-
- @Override
- public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {
- VariableMap valueMap = getValueVariableMap(graph, context);
- if(valueMap != null) return valueMap.getVariable(graph, context, name);
- return getStandardPropertyDomainPropertyVariableFromValue(graph, context, name);
- }
-
- @Override
- public Map<String, Variable> getVariables(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {
- VariableMap valueMap = getValueVariableMap(graph, context);
- if(valueMap != null) return valueMap.getVariables(graph, context, map);
- else return getStandardPropertyDomainPropertyVariablesFromValue(graph, context, map);
- }
-
- @Override
- public Map<String, Variable> getVariables(ReadGraph graph, Variable context, String classification, Map<String, Variable> map) throws DatabaseException {
- VariableMap valueMap = getValueVariableMap(graph, context);
- if(valueMap != null) return valueMap.getVariables(graph, context, classification, map);
- else return getStandardPropertyDomainPropertyVariablesFromValue(graph, context, classification, map);
- }
-
- };
+ public static VariableMap methodsPropertyDomainProperties = new VariableMapImpl() {
+
+ @Override
+ public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {
+ Variable parent = context.getParent(graph);
+ Resource container = parent.getPossibleRepresents(graph);
+ if(container == null)
+ return null;
+ Map<String,Resource> methods = graph.syncRequest(new UnescapedMethodMapOfResource(container));
+ Resource predicate = methods.get(name);
+ if(predicate != null) {
+ Layer0 L0 = Layer0.getInstance(graph);
+ PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(L0.Entity_method));
+ Resource value = graph.getSingleObject(container, predicate);
+ return new StandardGraphPropertyVariable(context, null, container, info, value);
+ }
+ return null;
+ }
+
+ @Override
+ public Map<String, Variable> getVariables(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {
+ Variable parent = context.getParent(graph);
+ Resource container = parent.getPossibleRepresents(graph);
+ if(container == null)
+ return Collections.emptyMap();
+ Map<String,Resource> methods = graph.syncRequest(new UnescapedMethodMapOfResource(container));
+ for(Map.Entry<String, Resource> entry : methods.entrySet()) {
+ String name = entry.getKey();
+ Resource predicate = entry.getValue();
+ Layer0 L0 = Layer0.getInstance(graph);
+ PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(L0.Entity_method));
+ Resource value = graph.getSingleObject(container, predicate);
+ if(map == null) map = new HashMap<>();
+ map.put(name, new StandardGraphPropertyVariable(context, null, container, info, value));
+ }
+ return map;
+ }
+
+ };
+
+ public static Variable getStandardPropertyDomainPropertyVariableFromValue(ReadGraph graph, Variable context, String name) throws DatabaseException {
+
+ if(context instanceof StandardGraphPropertyVariable) {
+ StandardGraphPropertyVariable variable = (StandardGraphPropertyVariable)context;
+ Resource literal = variable.getPossibleRepresents(graph);
+ Object propertyNode = getPossibleNodeProperty(graph, variable, name, false);
+
+ if(literal != null) {
+ Variable result = getPossiblePropertyFromContext(graph, variable, literal, name, propertyNode);
+ if(result != null) return result;
+ }
+
+ Variable result = getPossibleSubliteralPropertyFromContext(graph, variable, name);
+ if(result != null) return result;
+ result = getPossiblePropertyFromContext(graph, variable, variable.property.predicate, name, propertyNode);
+ if (result != null) return result;
+
+ // Get possible property from NodeManager
+ if (propertyNode != null)
+ return createStandardGraphPropertyVariable(graph, variable, propertyNode);
+ return null;
+ } else if (context instanceof StandardGraphChildVariable) {
+ return standardChildDomainProperties.getVariable(graph, context, name);
+ } else {
+ throw new DatabaseException("Unknown variable implementation " + context.getClass().getCanonicalName());
+ }
+
+ }
+
+ public static Map<String, Variable> getStandardPropertyDomainPropertyVariablesFromValue(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {
+
+ if(context instanceof StandardGraphPropertyVariable) {
+ StandardGraphPropertyVariable variable = (StandardGraphPropertyVariable)context;
+ map = collectPropertiesFromContext(graph, variable, variable.property.predicate, map);
+ if (variable.parentResource != null) {
+ Resource literal = graph.getPossibleObject(variable.parentResource, variable.property.predicate);
+ if(literal != null) map=collectPropertiesFromContext(graph, variable, literal, map);
+ map=collectSubliteralProperties(graph, variable, map);
+ }
+
+ // Get properties from VariableNode
+ map = getStandardNodePropertyVariables(graph, context, map);
+ return map;
+ } else if (context instanceof StandardGraphChildVariable) {
+ return standardChildDomainProperties.getVariables(graph, context, map);
+ } else {
+ throw new DatabaseException("Unknown variable implementation " + context.getClass().getCanonicalName());
+ }
+
+ }
+
+ public static Map<String, Variable> getStandardPropertyDomainPropertyVariablesFromValue(ReadGraph graph, Variable context, String classification, Map<String, Variable> map) throws DatabaseException {
+
+ if(context instanceof StandardGraphPropertyVariable) {
+ StandardGraphPropertyVariable variable = (StandardGraphPropertyVariable)context;
+ map = collectPropertiesFromContext(graph, variable, variable.property.predicate, classification, map);
+ if (variable.parentResource != null) {
+ Resource literal = graph.getPossibleObject(variable.parentResource, variable.property.predicate);
+ if(literal != null) map=collectPropertiesFromContext(graph, variable, literal, classification, map);
+ }
+
+ // Get properties from VariableNode
+ map = getStandardNodePropertyVariables(graph, context, map);
+ return map;
+ } else if (context instanceof StandardGraphChildVariable) {
+ return standardChildDomainProperties.getVariables(graph, context, map);
+ } else {
+ throw new DatabaseException("Unknown variable implementation " + context.getClass().getCanonicalName());
+ }
+
+ }
+
+ @SCLValue(type = "VariableMap")
+ public static VariableMap standardPropertyDomainProperties = new VariableMapImpl() {
+
+ VariableMap getValueVariableMap(ReadGraph graph, Variable context) throws DatabaseException {
+ Resource represents = context.getPossibleRepresents(graph);
+ if(represents == null) return null;
+
+ VariableMap map = graph.isImmutable(represents) ?
+ graph.syncRequest(new PropertyVariableMapRequest(represents), TransientCacheListener.<VariableMap>instance()) :
+ (VariableMap)graph.getPossibleRelatedValue2(represents, Layer0.getInstance(graph).domainProperties, represents);
+
+ if(map == standardPropertyDomainProperties) return null;
+ else return map;
+
+ }
+
+ @Override
+ public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {
+ VariableMap valueMap = getValueVariableMap(graph, context);
+ if(valueMap != null) return valueMap.getVariable(graph, context, name);
+ return getStandardPropertyDomainPropertyVariableFromValue(graph, context, name);
+ }
+
+ @Override
+ public Map<String, Variable> getVariables(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {
+ VariableMap valueMap = getValueVariableMap(graph, context);
+ if(valueMap != null) return valueMap.getVariables(graph, context, map);
+ else return getStandardPropertyDomainPropertyVariablesFromValue(graph, context, map);
+ }
+
+ @Override
+ public Map<String, Variable> getVariables(ReadGraph graph, Variable context, String classification, Map<String, Variable> map) throws DatabaseException {
+ VariableMap valueMap = getValueVariableMap(graph, context);
+ if(valueMap != null) return valueMap.getVariables(graph, context, classification, map);
+ else return getStandardPropertyDomainPropertyVariablesFromValue(graph, context, classification, map);
+ }
+
+ };