public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            object container = DestVar.GetVariableValue(procEnv);
            object key       = KeyExpression.Evaluate(procEnv);

            if (container is IList)
            {
                IList array = (IList)container;
                if (array.Count > (int)key)
                {
                    array[(int)key] = value;
                }
            }
            else if (container is IDeque)
            {
                IDeque deque = (IDeque)container;
                if (deque.Count > (int)key)
                {
                    deque[(int)key] = value;
                }
            }
            else
            {
                IDictionary map = (IDictionary)container;
                if (map.Contains(key))
                {
                    map[key] = value;
                }
            }
        }
        /// <summary>
        /// Returns a string representation of the given Deque
        /// </summary>
        /// <param name="deque">The Deque of which to get the string representation</param>
        /// <param name="type">The type as string, e.g deque<int></param>
        /// <param name="content">The content as string, e.g. ] 42, 43 [</param>
        /// <param name="attrType">The attribute type of the deque if available, otherwise null</param>
        /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
        /// <param name="firstLevelObjectEmitted">Prevents emitting of further objects and thus infinite regressions</param>
        /// <param name="nameToObject">If not null, the names of visited objects are added</param>
        /// <param name="procEnv">If not null, the processing environment is used for transient object unique id emitting and fetching</param>
        public static void ToString(IDeque deque, out string type, out string content,
                                    AttributeType attrType, IGraph graph, bool firstLevelObjectEmitted,
                                    IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            Type valueType;

            ContainerHelper.GetDequeType(deque, out valueType);

            StringBuilder sb = new StringBuilder(256);

            sb.Append("]");

            AttributeType attrValueType = attrType != null ? attrType.ValueType : null;

            if (deque != null)
            {
                type = "deque<" + valueType.Name + ">";
                AppendDeque(sb, deque, attrValueType, graph, firstLevelObjectEmitted, nameToObject, procEnv);
            }
            else
            {
                type = "<INVALID>";
            }

            sb.Append("[");
            content = sb.ToString();
        }
Beispiel #3
0
        public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            IGraphElement elem = (IGraphElement)DestVar.GetVariableValue(procEnv);
            AttributeType attrType;

            value = ContainerHelper.IfAttributeOfElementIsContainerThenCloneContainer(
                elem, AttributeName, value, out attrType);
            AttributeChangeType changeType = AttributeChangeType.Assign;

            if (elem is INode)
            {
                procEnv.Graph.ChangingNodeAttribute((INode)elem, attrType, changeType, value, null);
            }
            else
            {
                procEnv.Graph.ChangingEdgeAttribute((IEdge)elem, attrType, changeType, value, null);
            }
            elem.SetAttribute(AttributeName, value);
            if (elem is INode)
            {
                procEnv.Graph.ChangedNodeAttribute((INode)elem, attrType);
            }
            else
            {
                procEnv.Graph.ChangedEdgeAttribute((IEdge)elem, attrType);
            }
        }
        public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            IGraphElement elem        = (IGraphElement)GraphElementVar.GetVariableValue(procEnv);
            int           visitedFlag = VisitedFlagExpression != null ? (int)VisitedFlagExpression.Evaluate(procEnv) : 0;

            procEnv.Graph.SetVisited(elem, visitedFlag, (bool)value);
        }
 public void DoUndo(IGraphProcessingEnvironment procEnv)
 {
     // nothing to do, this is only needed to distinguish the outermost transaction
     // from the nested transactions to know when to remove the rollback information
     // if nothing happened from opening the first transaction to opening the transaction of interest,
     // they would be indistinguishable as the number of undo items did not change
 }
        public void DoUndo(IGraphProcessingEnvironment procEnv)
        {
            LGSPGraphProcessingEnvironment procEnv_ = (LGSPGraphProcessingEnvironment)procEnv;

            if (procEnv.Graph is LGSPNamedGraph)
            {
                if (_elem is LGSPNode)
                {
                    ((LGSPNamedGraph)procEnv_.graph).AddNode((LGSPNode)_elem, _name);
                }
                else
                {
                    ((LGSPNamedGraph)procEnv_.graph).AddEdge((LGSPEdge)_elem, _name);
                }
            }
            else
            {
                if (_elem is LGSPNode)
                {
                    procEnv_.graph.AddNode((LGSPNode)_elem);
                }
                else
                {
                    procEnv_.graph.AddEdge((LGSPEdge)_elem);
                }
            }

            if (_vars != null)
            {
                foreach (Variable var in _vars)
                {
                    procEnv_.SetVariableValue(var.Name, _elem);
                }
            }
        }
Beispiel #7
0
        protected static EdgeType GetEdgeType(IGraphProcessingEnvironment procEnv, SequenceExpression edgeTypeExpr, string functionName)
        {
            EdgeType edgeType = null;

            if (edgeTypeExpr != null) // often incident edge
            {
                object tmp = edgeTypeExpr.Evaluate(procEnv);
                if (tmp is string)
                {
                    edgeType = procEnv.Graph.Model.EdgeModel.GetType((string)tmp);
                }
                else if (tmp is EdgeType)
                {
                    edgeType = (EdgeType)tmp;
                }
                if (edgeType == null)
                {
                    throw new Exception("edge type argument to " + functionName + " is not an edge type");
                }
            }
            else
            {
                edgeType = procEnv.Graph.Model.EdgeModel.RootType;
            }

            return(edgeType);
        }
 public void DoUndo(IGraphProcessingEnvironment procEnv)
 {
     // nothing to do, this is only needed to distinguish the outermost transaction
     // from the nested transactions to know when to remove the rollback information
     // if nothing happened from opening the first transaction to opening the transaction of interest,
     // they would be indistinguishable as the number of undo items did not change
 }
Beispiel #9
0
        private static string ToString(IObject value, IGraph graph, bool firstLevelObjectEmitted,
                                       IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            StringBuilder sb         = new StringBuilder();
            string        objectType = value.Type.PackagePrefixedName;

            sb.Append(objectType);
            sb.Append("{");
            sb.Append("%:" + value.GetObjectName());
            if (nameToObject != null)
            {
                if (!nameToObject.ContainsKey(value.GetObjectName()))
                {
                    nameToObject.Add(value.GetObjectName(), value);
                }
            }
            if (!firstLevelObjectEmitted)
            {
                foreach (AttributeType attrType in value.Type.AttributeTypes)
                {
                    sb.Append(",");
                    sb.Append(attrType.Name);
                    sb.Append(":");
                    sb.Append(EmitHelper.ToStringAutomatic(value.GetAttribute(attrType.Name), graph, true,
                                                           nameToObject, procEnv));
                }
            }
            sb.Append("}");
            return(sb.ToString());
        }
Beispiel #10
0
        protected static NodeType GetNodeType(IGraphProcessingEnvironment procEnv, SequenceExpression nodeTypeExpr, string functionName)
        {
            NodeType nodeType = null;

            if (nodeTypeExpr != null) // often adjacent node
            {
                object tmp = nodeTypeExpr.Evaluate(procEnv);
                if (tmp is string)
                {
                    nodeType = procEnv.Graph.Model.NodeModel.GetType((string)tmp);
                }
                else if (tmp is NodeType)
                {
                    nodeType = (NodeType)tmp;
                }
                if (nodeType == null)
                {
                    throw new Exception("node type argument to " + functionName + " is not a node type");
                }
            }
            else
            {
                nodeType = procEnv.Graph.Model.NodeModel.RootType;
            }

            return(nodeType);
        }
        public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            IGraphElement elem = (IGraphElement)DestVar.GetVariableValue(procEnv);
            object container = elem.GetAttribute(AttributeName);
            object key = KeyExpression.Evaluate(procEnv);
            AttributeType attrType = elem.Type.GetAttributeType(AttributeName);

            BaseGraph.ChangingAttributeAssignElement(procEnv.Graph, elem, attrType, value, key);

            if(container is IList)
            {
                IList array = (IList)container;
                array[(int)key] = value;
            }
            else if(container is IDeque)
            {
                IDeque deque = (IDeque)container;
                deque[(int)key] = value;
            }
            else
            {
                IDictionary map = (IDictionary)container;
                map[key] = value;
            }

            BaseGraph.ChangedAttribute(procEnv.Graph, elem, attrType);
        }
Beispiel #12
0
        /// <summary>
        /// Returns a string representation of the given scalar value
        /// </summary>
        /// <param name="value">The scalar value of which to get the string representation</param>
        /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
        /// <param name="firstLevelObjectEmitted">Prevents emitting of further objects and thus infinite regressions</param>
        /// <param name="nameToObject">If not null, the names of visited objects are added</param>
        /// <param name="procEnv">If not null, the processing environment is used for transient object unique id emitting and fetching</param>
        /// <returns>string representation of scalar value</returns>
        public static string ToString(object value, IGraph graph, bool firstLevelObjectEmitted,
                                      IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            string type;
            string content;

            ToString(value, out type, out content, null, graph, firstLevelObjectEmitted, nameToObject, procEnv);
            return(content);
        }
 public void DoUndo(IGraphProcessingEnvironment procEnv)
 {
     if (_elem is INode)
     {
         procEnv.Graph.Remove((INode)_elem);
     }
     else
     {
         procEnv.Graph.Remove((IEdge)_elem);
     }
 }
Beispiel #14
0
        // gets the variable value, decides whether to query the graph-global or the sequence-lokal variables
        public object GetVariableValue(IGraphProcessingEnvironment procEnv)
        {
            if(Type == "") {
                return procEnv.GetVariableValue(name);
            } else {
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + "==" + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                return value;
            }
        }
Beispiel #15
0
        public static IList GroupBy(object container, string memberOrAttribute, IGraphProcessingEnvironment procEnv)
        {
            IList array          = (IList)container;
            IList resultingArray = procEnv.Actions.ArrayGroupBy(array, memberOrAttribute);

            if (resultingArray != null)
            {
                return(resultingArray);
            }
            return(procEnv.Graph.Model.ArrayGroupBy(array, memberOrAttribute));
        }
Beispiel #16
0
 private bool If(IGraphElement element, IGraphProcessingEnvironment procEnv)
 {
     if (ifClause != null)
     {
         object oldThis = procEnv.GetVariableValue("this");
         procEnv.SetVariableValue("this", element);
         bool result = (bool)ifClause.Evaluate(procEnv);
         procEnv.SetVariableValue("this", oldThis);
         return(result);
     }
     return(true);
 }
Beispiel #17
0
        public ShellGraphProcessingEnvironment(INamedGraph graph, String backendFilename, String[] backendParameters, String modelFilename)
        {
            LGSPNamedGraph Graph = (LGSPNamedGraph)graph;

            DumpInfo           = new DumpInfo(Graph.GetElementName);
            SubruleDebugConfig = new SubruleDebuggingConfiguration();
            BackendFilename    = backendFilename;
            BackendParameters  = backendParameters;
            ModelFilename      = modelFilename;
            ProcEnv            = new LGSPGraphProcessingEnvironment(Graph, null);
            NameToSubgraph.Add(Graph.Name, Graph);
        }
        public override void Assign(object value, IGraphProcessingEnvironment procEnv)
        {
            IGraphElement elem = (IGraphElement)DestVar.GetVariableValue(procEnv);
            AttributeType attrType;
            value = ContainerHelper.IfAttributeOfElementIsContainerThenCloneContainer(
                elem, AttributeName, value, out attrType);

            BaseGraph.ChangingAttributeAssign(procEnv.Graph, elem, attrType, value);

            elem.SetAttribute(AttributeName, value);

            BaseGraph.ChangedAttribute(procEnv.Graph, elem, attrType);
        }
Beispiel #19
0
        // gets the variable value, decides whether to query the graph-global or the sequence-lokal variables
        public object GetVariableValue(IGraphProcessingEnvironment procEnv)
        {
            if (Type == "")
            {
                return(procEnv.GetVariableValue(name));
            }
            else
            {
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + "==" + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                return(value);
            }
        }
Beispiel #20
0
        // sets the variable value, decides whether to update the graph-global or the sequence-lokal variables
        public void SetVariableValue(object value, IGraphProcessingEnvironment procEnv)
        {
            if (Type == "")
            {
                procEnv.SetVariableValue(name, value);
            }
            else
            {
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + " = " + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                this.value = value;
            }
        }
Beispiel #21
0
        /// <summary>
        /// Returns type object for type name string
        /// </summary>
        /// <param name="typeName">Name of the type we want some type object for</param>
        /// <param name="procEnv">Graph processing environment to search the types in</param>
        /// <returns>The type object corresponding to the given string, null if type was not found</returns>
        public static Type GetType(String typeName, IGraphProcessingEnvironment procEnv)
        {
            if (typeName == null)
            {
                return(null);
            }

            if (procEnv == null)
            {
                return(null);
            }

            Type typeFromModel = GetType(typeName, procEnv.Graph.Model);

            if (typeFromModel != null)
            {
                return(typeFromModel);
            }

            IActions actions = procEnv.Actions;

            Assembly assembly = Assembly.GetAssembly(actions.GetType());

            typeName = typeName.Substring(6);                      // remove "match<"
            typeName = typeName.Substring(0, typeName.Length - 1); // remove ">"
            if (typeName.StartsWith("class "))
            {
                typeName = typeName.Substring(6); // remove "class "
            }
            foreach (IAction action in actions.Actions)
            {
                if (action.PackagePrefixedName == typeName)
                {
                    Type type = Type.GetType(action.RulePattern.MatchInterfaceName + "," + assembly.FullName); // search actions assembly
                    return(type);
                }
            }

            foreach (MatchClassFilterer matchClassFilterer in actions.MatchClasses)
            {
                MatchClassInfo info = matchClassFilterer.info;
                if (info.PackagePrefixedName == typeName)
                {
                    Type type = Type.GetType(info.matchInterfaceName + "," + assembly.FullName); // search actions assembly
                    return(type);
                }
            }

            return(null);
        }
        public void DoUndo(IGraphProcessingEnvironment procEnv)
        {
            String name;

            if (procEnv.Graph is LGSPNamedGraph && ((LGSPNamedGraph)procEnv.Graph).ElemToName.TryGetValue(_newElem, out name))
            {
                LGSPNamedGraph lgspGraph = (LGSPNamedGraph)procEnv.Graph;
                if (_newElem is INode)
                {
                    LGSPNode newNode = (LGSPNode)_newElem;
                    LGSPNode oldNode = (LGSPNode)_oldElem;
                    lgspGraph.ElemToName[oldNode] = name;
                    lgspGraph.RetypingNode(newNode, oldNode); // this will switch the variables
                    lgspGraph.ReplaceNode(newNode, oldNode);
                    lgspGraph.ElemToName.Remove(newNode);
                    lgspGraph.NameToElem[name] = oldNode;
                }
                else
                {
                    LGSPEdge newEdge = (LGSPEdge)_newElem;
                    LGSPEdge oldEdge = (LGSPEdge)_oldElem;
                    lgspGraph.ElemToName[oldEdge] = name;
                    lgspGraph.RetypingEdge(newEdge, oldEdge); // this will switch the variables
                    lgspGraph.ReplaceEdge(newEdge, oldEdge);
                    lgspGraph.ElemToName.Remove(newEdge);
                    lgspGraph.NameToElem[name] = oldEdge;
                }
            }
            else
            {
                LGSPGraph lgspGraph = (LGSPGraph)procEnv.Graph;
                if (_newElem is INode)
                {
                    LGSPNode newNode = (LGSPNode)_newElem;
                    LGSPNode oldNode = (LGSPNode)_oldElem;
                    lgspGraph.RetypingNode(newNode, oldNode); // this will switch the variables
                    lgspGraph.ReplaceNode(newNode, oldNode);
                }
                else
                {
                    LGSPEdge newEdge = (LGSPEdge)_newElem;
                    LGSPEdge oldEdge = (LGSPEdge)_oldElem;
                    lgspGraph.RetypingEdge(newEdge, oldEdge); // this will switch the variables
                    lgspGraph.ReplaceEdge(newEdge, oldEdge);
                }
            }
        }
Beispiel #23
0
 public static object InContainer(IGraphProcessingEnvironment procEnv, object container, object value)
 {
     if (container is IList)
     {
         IList array = (IList)container;
         return(array.Contains(value));
     }
     else if (container is IDeque)
     {
         IDeque deque = (IDeque)container;
         return(deque.Contains(value));
     }
     else
     {
         IDictionary setmap = (IDictionary)container;
         return(setmap.Contains(value));
     }
 }
Beispiel #24
0
 public static bool ContainerEmpty(IGraphProcessingEnvironment procEnv, object container)
 {
     if (container is IList)
     {
         IList array = (IList)container;
         return(array.Count == 0);
     }
     else if (container is IDeque)
     {
         IDeque deque = (IDeque)container;
         return(deque.Count == 0);
     }
     else
     {
         IDictionary setmap = (IDictionary)container;
         return(setmap.Count == 0);
     }
 }
Beispiel #25
0
 public static object ContainerAccess(IGraphProcessingEnvironment procEnv, object container, object key)
 {
     if (container is IList)
     {
         IList array = (IList)container;
         return(array[(int)key]);
     }
     else if (container is IDeque)
     {
         IDeque deque = (IDeque)container;
         return(deque[(int)key]);
     }
     else
     {
         IDictionary setmap = (IDictionary)container;
         return(setmap[key]);
     }
 }
Beispiel #26
0
 /// <summary>
 /// Filters the matches of a multi rule all call or multi rule backtracking construct
 /// (i.e. matches obtained from different rules, that implement a match class)
 /// with a lambda expression filter (call).
 /// </summary>
 /// <param name="procEnv">The graph processing environment, required by the filter implementation.</param>
 /// <param name="matches">The combined list of all matches of all rules (implementing the same match class; to inspect and filter)</param>
 /// <param name="filter">The lambda expression filter to apply</param>
 public void Filter(IGraphProcessingEnvironment procEnv, IList <IMatch> matches, FilterCallWithLambdaExpression filter)
 {
     if (filter.PlainName == "assign")
     {
         FilterAssign(procEnv, matches, filter);
     }
     else if (filter.PlainName == "removeIf")
     {
         FilterRemoveIf(procEnv, matches, filter);
     }
     else if (filter.PlainName == "assignStartWithAccumulateBy")
     {
         FilterAssignStartWithAccumulateBy(procEnv, matches, filter);
     }
     else
     {
         throw new Exception("Unknown lambda expression filter call (available are assign, removeIf, assignStartWithAccumulateBy)");
     }
 }
Beispiel #27
0
        private static string ToString(ITransientObject value, IGraph graph, bool firstLevelObjectEmitted,
                                       IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            StringBuilder sb = new StringBuilder();
            string        transientObjectType = value.Type.PackagePrefixedName;

            sb.Append(transientObjectType);
            if (procEnv != null || !firstLevelObjectEmitted)
            {
                sb.Append("{");
            }
            bool first = true;

            if (procEnv != null)
            {
                sb.Append("&:" + procEnv.GetUniqueId(value));
                first = false;
            }
            if (!firstLevelObjectEmitted)
            {
                foreach (AttributeType attrType in value.Type.AttributeTypes)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }
                    sb.Append(attrType.Name);
                    sb.Append(":");
                    sb.Append(EmitHelper.ToStringAutomatic(value.GetAttribute(attrType.Name), graph, true,
                                                           nameToObject, procEnv));
                }
            }
            if (procEnv != null || !firstLevelObjectEmitted)
            {
                sb.Append("}");
            }
            return(sb.ToString());
        }
Beispiel #28
0
        public SequenceVariable Copy(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
        {
            // ensure that every instance of a variable is mapped to the same copy
            if(originalToCopy.ContainsKey(this))
                return originalToCopy[this];

            // local variables must be cloned when a defined sequence gets copied
            // global variables stay the same
            if(Type == "")
            {
                originalToCopy.Add(this, this);
                return this;
            }
            else
            {
                originalToCopy.Add(this, new SequenceVariable(name, prefix, type));
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + " = " + name + "; " + name + "==" + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                return originalToCopy[this];
            }
        }
        /// <summary>
        /// Returns a string representation of the given non-container value
        /// </summary>
        /// <param name="value">The scalar value of which to get the string representation</param>
        /// <param name="type">The type as string, e.g int,string,Foo </param>
        /// <param name="content">The content as string, e.g. 42,"foo",bar } </param>
        /// <param name="attrType">The attribute type of the value (may be null)</param>
        /// <param name="graph">The graph with the model and the element names</param>
        /// <param name="firstLevelObjectEmitted">Prevents emitting of further objects and thus infinite regressions</param>
        /// <param name="nameToObject">If not null, the names of visited objects are added</param>
        /// <param name="procEnv">If not null, the processing environment is used for transient object unique id emitting and fetching</param>
        public static void ToString(object value, out string type, out string content,
                                    AttributeType attrType, IGraph graph, bool firstLevelObjectEmitted,
                                    IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            if (attrType == null)
            {
                ToString(value, out type, out content, graph, firstLevelObjectEmitted, nameToObject, procEnv);
                return;
            }

            Debug.Assert(attrType.Kind != AttributeKind.SetAttr && attrType.Kind != AttributeKind.MapAttr &&
                         attrType.Kind != AttributeKind.ArrayAttr && attrType.Kind != AttributeKind.DequeAttr);
            type = TypesHelper.AttributeTypeToXgrsType(attrType);

            if (type == "object")
            {
                content = ToStringObject(value, attrType, graph);
            }
            else
            {
                content = ToString(value, attrType, graph, firstLevelObjectEmitted, nameToObject, procEnv);
            }
        }
Beispiel #30
0
 public void FilterAssign(IGraphProcessingEnvironment procEnv, IList <IMatch> matchList, FilterCallWithLambdaExpression filterCall)
 {
     if (filterCall.arrayAccess != null)
     {
         List <IMatch> matchListCopy = new List <IMatch>();
         foreach (IMatch match in matchList)
         {
             matchListCopy.Add(match.Clone());
         }
         filterCall.arrayAccess.SetVariableValue(matchListCopy, procEnv);
     }
     for (int index = 0; index < matchList.Count; ++index)
     {
         if (filterCall.index != null)
         {
             filterCall.index.SetVariableValue(index, procEnv);
         }
         IMatch match = matchList[index];
         filterCall.element.SetVariableValue(match, procEnv);
         object result = filterCall.lambdaExpression.Evaluate(procEnv);
         match.SetMember(filterCall.Entity, result);
     }
 }
        /// <summary>
        /// Returns a string representation of the given dictionary
        /// </summary>
        /// <param name="setmap">The dictionary of which to get the string representation</param>
        /// <param name="type">The type as string, e.g set<int> or map<string,boolean> </param>
        /// <param name="content">The content as string, e.g. { 42, 43 } or { "foo"->true, "bar"->false } </param>
        /// <param name="attrType">The attribute type of the dictionary if available, otherwise null</param>
        /// <param name="graph">The graph with the model and the element names if available, otherwise null</param>
        /// <param name="firstLevelObjectEmitted">Prevents emitting of further objects and thus infinite regressions</param>
        /// <param name="nameToObject">If not null, the names of visited objects are added</param>
        /// <param name="procEnv">If not null, the processing environment is used for transient object unique id emitting and fetching</param>
        public static void ToString(IDictionary setmap, out string type, out string content,
                                    AttributeType attrType, IGraph graph, bool firstLevelObjectEmitted,
                                    IDictionary <string, IObject> nameToObject, IGraphProcessingEnvironment procEnv)
        {
            Type keyType;
            Type valueType;

            ContainerHelper.GetDictionaryTypes(setmap, out keyType, out valueType);

            StringBuilder sb = new StringBuilder(256);

            sb.Append("{");

            AttributeType attrValueType = attrType != null ? attrType.ValueType : null;
            AttributeType attrKeyType   = attrType != null ? attrType.KeyType : null;

            if (setmap != null)
            {
                if (valueType == typeof(SetValueType))
                {
                    type = "set<" + keyType.Name + ">";
                    AppendSet(sb, setmap, attrValueType, graph, firstLevelObjectEmitted, nameToObject, procEnv);
                }
                else
                {
                    type = "map<" + keyType.Name + "," + valueType.Name + ">";
                    AppendMap(sb, setmap, attrKeyType, attrValueType, graph, firstLevelObjectEmitted, nameToObject, procEnv);
                }
            }
            else
            {
                type = "<INVALID>";
            }

            sb.Append("}");
            content = sb.ToString();
        }
Beispiel #32
0
        public void FilterRemoveIf(IGraphProcessingEnvironment procEnv, IList <IMatch> matchList, FilterCallWithLambdaExpression filterCall)
        {
            List <IMatch> matchListCopy = new List <IMatch>(matchList);

            if (filterCall.arrayAccess != null)
            {
                filterCall.arrayAccess.SetVariableValue(matchListCopy, procEnv);
            }
            matchList.Clear();
            for (int index = 0; index < matchListCopy.Count; ++index)
            {
                if (filterCall.index != null)
                {
                    filterCall.index.SetVariableValue(index, procEnv);
                }
                IMatch match = matchListCopy[index];
                filterCall.element.SetVariableValue(match, procEnv);
                object result = filterCall.lambdaExpression.Evaluate(procEnv);
                if (!(bool)result)
                {
                    matchList.Add(match);
                }
            }
        }
Beispiel #33
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionFunctionMethodCall copy = (SequenceExpressionFunctionMethodCall)MemberwiseClone();
     copy.TargetExpr = TargetExpr.CopyExpression(originalToCopy, procEnv);
     copy.ParamBindings = ParamBindings.Copy(originalToCopy, procEnv);
     return copy;
 }
Beispiel #34
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     object subgraph = Subgraph.Evaluate(procEnv);
     object subgraphSet = SubgraphSet.Evaluate(procEnv);
     return GraphHelper.EqualsAny((IGraph)subgraph, (IDictionary<IGraph, SetValueType>)subgraphSet, IncludingAttributes);
 }
Beispiel #35
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionCountBoundedReachable copy = (SequenceExpressionCountBoundedReachable)MemberwiseClone();
     copy.SourceNode = SourceNode.CopyExpression(originalToCopy, procEnv);
     copy.Depth = Depth.CopyExpression(originalToCopy, procEnv);
     if(EdgeType != null) copy.EdgeType = EdgeType.CopyExpression(originalToCopy, procEnv);
     if(OppositeNodeType!=null)copy.OppositeNodeType = OppositeNodeType.CopyExpression(originalToCopy, procEnv);
     return copy;
 }
Beispiel #36
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionIsAdjacentIncident copy = (SequenceExpressionIsAdjacentIncident)MemberwiseClone();
     copy.SourceNode = SourceNode.CopyExpression(originalToCopy, procEnv);
     copy.EndElement = EndElement.CopyExpression(originalToCopy, procEnv);
     if(EdgeType != null) copy.EdgeType = EdgeType.CopyExpression(originalToCopy, procEnv);
     if(OppositeNodeType!=null)copy.OppositeNodeType = OppositeNodeType.CopyExpression(originalToCopy, procEnv);
     return copy;
 }
Beispiel #37
0
        // sets the variable value, decides whether to update the graph-global or the sequence-lokal variables
        public void SetVariableValue(object value, IGraphProcessingEnvironment procEnv)
        {
            if(Type == "") {
                procEnv.SetVariableValue(name, value);
            } else {
#if LOG_VARIABLE_OPERATIONS
                procEnv.Recorder.Write(name + " = " + EmitHelper.ToStringAutomatic(value, procEnv.Graph) + "\n");
#endif
                this.value = value;
            }
        }
Beispiel #38
0
        public override object Execute(IGraphProcessingEnvironment procEnv)
        {
            object leftValue = Left.Evaluate(procEnv);
            object rightValue = Right.Evaluate(procEnv);

            try
            {
                return SequenceExpressionHelper.StructuralEqualObjects(leftValue, rightValue);
            }
            catch(Exception)
            {
                throw new SequenceParserException(Operator, TypesHelper.XgrsTypeOfConstant(leftValue, procEnv.Graph.Model), TypesHelper.XgrsTypeOfConstant(rightValue, procEnv.Graph.Model), Symbol);
            }
        }
Beispiel #39
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     object nodeSet = NodeSet.Evaluate(procEnv);
     return GraphHelper.InducedSubgraph((IDictionary<INode, SetValueType>)nodeSet, procEnv.Graph);
 }
Beispiel #40
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionTypeof copy = (SequenceExpressionTypeof)MemberwiseClone();
     copy.Entity = Entity.CopyExpression(originalToCopy, procEnv);
     return copy;
 }
Beispiel #41
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     object entity = Entity.Evaluate(procEnv);
     return TypesHelper.XgrsTypeOfConstant(entity, procEnv.Graph.Model);
 }
Beispiel #42
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     if(UniquelyIdentifiedEntity != null)
         return GraphHelper.Uniqueof(UniquelyIdentifiedEntity.Evaluate(procEnv), procEnv.Graph);
     else
         return GraphHelper.Uniqueof(null, procEnv.Graph);
 }
Beispiel #43
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionUniqueof copy = (SequenceExpressionUniqueof)MemberwiseClone();
     if(UniquelyIdentifiedEntity != null)
         copy.UniquelyIdentifiedEntity = UniquelyIdentifiedEntity.CopyExpression(originalToCopy, procEnv);
     return copy;
 }
Beispiel #44
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     object graph = Graph.Evaluate(procEnv);
     return ((IGraph)graph).Canonize();
 }
Beispiel #45
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     IGraphElement owner = (IGraphElement)TargetExpr.Evaluate(procEnv);
     for(int i = 0; i < ParamBindings.ArgumentExpressions.Length; i++)
     {
         if(ParamBindings.ArgumentExpressions[i] != null)
             ParamBindings.Arguments[i] = ParamBindings.ArgumentExpressions[i].Evaluate(procEnv);
     }
     return owner.ApplyFunctionMethod(procEnv, procEnv.Graph, ParamBindings.Name, ParamBindings.Arguments);
 }
Beispiel #46
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     object path = Path.Evaluate(procEnv);
     return File.Exists((string)path);
 }
Beispiel #47
0
        public override object Execute(IGraphProcessingEnvironment procEnv)
        {
            object leftValue = Left.Evaluate(procEnv);
            object rightValue = Right.Evaluate(procEnv);

            string balancedType = BalancedTypeStatic;
            string leftType = LeftTypeStatic;
            string rightType = RightTypeStatic;
            if(balancedType == "")
            {
                leftType = TypesHelper.XgrsTypeOfConstant(leftValue, procEnv.Graph.Model);
                rightType = TypesHelper.XgrsTypeOfConstant(rightValue, procEnv.Graph.Model);
                balancedType = SequenceExpressionHelper.Balance(SequenceExpressionType, leftType, rightType, procEnv.Graph.Model);
                if(balancedType == "-")
                {
                    throw new SequenceParserException(Operator, leftType, rightType, Symbol);
                }
            }

            try
            {
                return SequenceExpressionHelper.ModObjects(leftValue, rightValue, balancedType, leftType, rightType, procEnv.Graph);
            }
            catch(Exception)
            {
                throw new SequenceParserException(Operator, TypesHelper.XgrsTypeOfConstant(leftValue, procEnv.Graph.Model), TypesHelper.XgrsTypeOfConstant(rightValue, procEnv.Graph.Model), Symbol);
            }
        }
Beispiel #48
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionImport copy = (SequenceExpressionImport)MemberwiseClone();
     copy.Path = Path.CopyExpression(originalToCopy, procEnv);
     return copy;
 }
Beispiel #49
0
        public override object Execute(IGraphProcessingEnvironment procEnv)
        {
            INode sourceNode = (INode)SourceNode.Evaluate(procEnv);
            IGraphElement endElement = (IGraphElement)EndElement.Evaluate(procEnv);
            EdgeType edgeType = null;
            if(EdgeType != null)
            {
                object tmp = EdgeType.Evaluate(procEnv);
                if(tmp is string) edgeType = procEnv.Graph.Model.EdgeModel.GetType((string)tmp);
                else if(tmp is EdgeType) edgeType = (EdgeType)tmp;
                if(edgeType == null) throw new Exception("edge type argument to " + FunctionSymbol + " is not an edge type");
            }
            else
            {
                edgeType = procEnv.Graph.Model.EdgeModel.RootType;
            }
            NodeType nodeType = null;
            if(OppositeNodeType != null)
            {
                object tmp = OppositeNodeType.Evaluate(procEnv);
                if(tmp is string) nodeType = procEnv.Graph.Model.NodeModel.GetType((string)tmp);
                else if(tmp is NodeType) nodeType = (NodeType)tmp;
                if(nodeType == null) throw new Exception("node type argument to " + FunctionSymbol + " is not a node type");
            }
            else
            {
                nodeType = procEnv.Graph.Model.NodeModel.RootType;
            }

            switch(SequenceExpressionType)
            {
                case SequenceExpressionType.IsReachableNodes:
                    if(EmitProfiling)
                        return GraphHelper.IsReachable(procEnv.Graph, sourceNode, (INode)endElement, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.IsReachable(procEnv.Graph, sourceNode, (INode)endElement, edgeType, nodeType);
                case SequenceExpressionType.IsReachableNodesViaIncoming:
                    if(EmitProfiling)
                        return GraphHelper.IsReachableIncoming(procEnv.Graph, sourceNode, (INode)endElement, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.IsReachableIncoming(procEnv.Graph, sourceNode, (INode)endElement, edgeType, nodeType);
                case SequenceExpressionType.IsReachableNodesViaOutgoing:
                    if(EmitProfiling)
                        return GraphHelper.IsReachableOutgoing(procEnv.Graph, sourceNode, (INode)endElement, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.IsReachableOutgoing(procEnv.Graph, sourceNode, (INode)endElement, edgeType, nodeType);
                case SequenceExpressionType.IsReachableEdges:
                    if(EmitProfiling)
                        return GraphHelper.IsReachableEdges(procEnv.Graph, sourceNode, (IEdge)endElement, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.IsReachableEdges(procEnv.Graph, sourceNode, (IEdge)endElement, edgeType, nodeType);
                case SequenceExpressionType.IsReachableEdgesViaIncoming:
                    if(EmitProfiling)
                        return GraphHelper.IsReachableEdgesIncoming(procEnv.Graph, sourceNode, (IEdge)endElement, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.IsReachableEdgesIncoming(procEnv.Graph, sourceNode, (IEdge)endElement, edgeType, nodeType);
                case SequenceExpressionType.IsReachableEdgesViaOutgoing:
                    if(EmitProfiling)
                        return GraphHelper.IsReachableEdgesOutgoing(procEnv.Graph, sourceNode, (IEdge)endElement, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.IsReachableEdgesOutgoing(procEnv.Graph, sourceNode, (IEdge)endElement, edgeType, nodeType);
                default:
                    return null; // internal failure
            }
        }
Beispiel #50
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     object path = Path.Evaluate(procEnv);
     return GraphHelper.Import(path, procEnv.Graph);
 }
Beispiel #51
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     return Operand.Evaluate(procEnv);
 }
Beispiel #52
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionCopy copy = (SequenceExpressionCopy)MemberwiseClone();
     copy.ObjectToBeCopied = ObjectToBeCopied.CopyExpression(originalToCopy, procEnv);
     return copy;
 }
Beispiel #53
0
 internal override sealed SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionCast copy = (SequenceExpressionCast)MemberwiseClone();
     copy.Operand = Operand.CopyExpression(originalToCopy, procEnv);
     copy.TargetType = TargetType;
     return copy;
 }
Beispiel #54
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     object toBeCloned = ObjectToBeCopied.Evaluate(procEnv);
     if(toBeCloned is IGraph)
         return GraphHelper.Copy((IGraph)toBeCloned);
     else if(toBeCloned is IMatch)
         return ((IMatch)toBeCloned).Clone();
     else
         return ContainerHelper.Clone(toBeCloned);
 }
Beispiel #55
0
        public override object Execute(IGraphProcessingEnvironment procEnv)
        {
            INode sourceNode = (INode)SourceNode.Evaluate(procEnv);
            int depth = (int)Depth.Evaluate(procEnv);
            EdgeType edgeType = null;
            if(EdgeType != null)
            {
                object tmp = EdgeType.Evaluate(procEnv);
                if(tmp is string) edgeType = procEnv.Graph.Model.EdgeModel.GetType((string)tmp);
                else if(tmp is EdgeType) edgeType = (EdgeType)tmp;
                if(edgeType == null) throw new Exception("edge type argument to " + FunctionSymbol + " is not an edge type");
            }
            else
            {
                edgeType = procEnv.Graph.Model.EdgeModel.RootType;
            }
            NodeType nodeType = null;
            if(OppositeNodeType != null)
            {
                object tmp = OppositeNodeType.Evaluate(procEnv);
                if(tmp is string) nodeType = procEnv.Graph.Model.NodeModel.GetType((string)tmp);
                else if(tmp is NodeType) nodeType = (NodeType)tmp;
                if(nodeType == null) throw new Exception("node type argument to " + FunctionSymbol + " is not a node type");
            }
            else
            {
                nodeType = procEnv.Graph.Model.NodeModel.RootType;
            }

            switch(SequenceExpressionType)
            {
                case SequenceExpressionType.BoundedReachableNodesWithRemainingDepth:
                    if(EmitProfiling)
                        return GraphHelper.BoundedReachableWithRemainingDepth(sourceNode, depth, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.BoundedReachableWithRemainingDepth(sourceNode, depth, edgeType, nodeType);
                case SequenceExpressionType.BoundedReachableNodesWithRemainingDepthViaIncoming:
                    if(EmitProfiling)
                        return GraphHelper.BoundedReachableWithRemainingDepthIncoming(sourceNode, depth, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.BoundedReachableWithRemainingDepthIncoming(sourceNode, depth, edgeType, nodeType);
                case SequenceExpressionType.BoundedReachableNodesWithRemainingDepthViaOutgoing:
                    if(EmitProfiling)
                        return GraphHelper.BoundedReachableWithRemainingDepthOutgoing(sourceNode, depth, edgeType, nodeType, procEnv);
                    else
                        return GraphHelper.BoundedReachableWithRemainingDepthOutgoing(sourceNode, depth, edgeType, nodeType);
                default:
                    return null; // internal failure
            }
        }
Beispiel #56
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     IFunctionDefinition funcDef = ParamBindings.FunctionDef;
     for(int i = 0; i < ParamBindings.ArgumentExpressions.Length; i++)
     {
         if(ParamBindings.ArgumentExpressions[i] != null)
             ParamBindings.Arguments[i] = ParamBindings.ArgumentExpressions[i].Evaluate(procEnv);
     }
     object res = funcDef.Apply(procEnv, procEnv.Graph, ParamBindings);
     return res;
 }
Beispiel #57
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionDefinedSubgraph copy = (SequenceExpressionDefinedSubgraph)MemberwiseClone();
     copy.EdgeSet = EdgeSet.CopyExpression(originalToCopy, procEnv);
     return copy;
 }
Beispiel #58
0
 internal override SequenceExpression CopyExpression(Dictionary<SequenceVariable, SequenceVariable> originalToCopy, IGraphProcessingEnvironment procEnv)
 {
     SequenceExpressionEqualsAny copy = (SequenceExpressionEqualsAny)MemberwiseClone();
     copy.Subgraph = Subgraph.CopyExpression(originalToCopy, procEnv);
     copy.SubgraphSet = SubgraphSet.CopyExpression(originalToCopy, procEnv);
     return copy;
 }
 public override sealed object Execute(IGraphProcessingEnvironment procEnv)
 {
     throw new Exception("Internal error! AssignmentTarget executed as SequenceComputation.");
 }
Beispiel #60
0
 public override object Execute(IGraphProcessingEnvironment procEnv)
 {
     object edgeSet = EdgeSet.Evaluate(procEnv);
     return GraphHelper.DefinedSubgraph((IDictionary<IEdge, SetValueType>)edgeSet, procEnv.Graph);
 }