public ComplexNodePattern(IBiFunction <M, K, object> getter, IList <Pair <K, NodePattern> > annotationPatterns) { // TODO: Change/Augment from list of class to pattern to list of conditions for matching // (so we can have more flexible matches) this.annotationPatterns = annotationPatterns; this.getter = getter; }
/// <summary> /// Adds the fold step to this <see cref="GraphTraversal{SType, EType}"/>. /// </summary> public static GraphTraversal <object, E2> Fold <E2>(this ITraversal traversal, E2 seed, IBiFunction foldFunction) { return(traversal.AsGraphTraversal <object, E2>().Fold(seed, foldFunction)); }
public static Edu.Stanford.Nlp.Ling.Tokensregex.ComplexNodePattern ValueOf <M, K>(Env env, IDictionary <string, string> attributes, IBiFunction <M, K, object> getter, Func <Pair <Env, string>, K> getKey) { Edu.Stanford.Nlp.Ling.Tokensregex.ComplexNodePattern <M, K> p = new Edu.Stanford.Nlp.Ling.Tokensregex.ComplexNodePattern <M, K>(getter, new List <Pair <K, NodePattern> >(attributes.Count)); p.Populate(env, attributes, getKey); return(p); }
public ComplexNodePattern(IBiFunction <M, K, object> getter, K key, NodePattern pattern) : this(getter, Pair.MakePair(key, pattern)) { }
public ComplexNodePattern(IBiFunction <M, K, object> getter, params Pair <K, NodePattern>[] annotationPatterns) { this.annotationPatterns = Arrays.AsList(annotationPatterns); this.getter = getter; }
/// <summary> /// Marginalizes out a variable by applying an associative join operation for each possible assignment to the /// marginalized variable. /// </summary> /// <param name="variable">the variable (by 'name', not offset into neighborIndices)</param> /// <param name="startingValue">associativeJoin is basically a foldr over a table, and this is the initialization</param> /// <param name="curriedFoldr"> /// the associative function to use when applying the join operation, taking first the /// assignment to the value being marginalized, and then a foldr operation /// </param> /// <returns> /// a new TableFactor that doesn't contain 'variable', where values were gotten through associative /// marginalization. /// </returns> private Edu.Stanford.Nlp.Loglinear.Inference.TableFactor Marginalize(int variable, double startingValue, IBiFunction <int, int[], IBiFunction <double, double, double> > curriedFoldr) { // Can't marginalize the last variable System.Diagnostics.Debug.Assert((GetDimensions().Length > 1)); // Calculate the result domain IList <int> resultDomain = new List <int>(); foreach (int n in neighborIndices) { if (n != variable) { resultDomain.Add(n); } } // Create result TableFactor int[] resultNeighborIndices = new int[resultDomain.Count]; int[] resultDimensions = new int[resultNeighborIndices.Length]; for (int i = 0; i < resultDomain.Count; i++) { int var = resultDomain[i]; resultNeighborIndices[i] = var; resultDimensions[i] = GetVariableSize(var); } Edu.Stanford.Nlp.Loglinear.Inference.TableFactor result = new Edu.Stanford.Nlp.Loglinear.Inference.TableFactor(resultNeighborIndices, resultDimensions); // Calculate forward-pointers from the old domain to new domain int[] mapping = new int[neighborIndices.Length]; for (int i_1 = 0; i_1 < neighborIndices.Length; i_1++) { mapping[i_1] = resultDomain.IndexOf(neighborIndices[i_1]); } // Initialize foreach (int[] assignment in result) { result.SetAssignmentLogValue(assignment, startingValue); } // Do the actual fold into the result int[] resultAssignment = new int[result.neighborIndices.Length]; int marginalizedVariableValue = 0; // OPTIMIZATION: // Rather than use the standard iterator, which creates lots of int[] arrays on the heap, which need to be GC'd, // we use the fast version that just mutates one array. Since this is read once for us here, this is ideal. IEnumerator <int[]> fastPassByReferenceIterator = FastPassByReferenceIterator(); int[] assignment_1 = fastPassByReferenceIterator.Current; while (true) { // Set the assignment arrays correctly for (int i_2 = 0; i_2 < assignment_1.Length; i_2++) { if (mapping[i_2] != -1) { resultAssignment[mapping[i_2]] = assignment_1[i_2]; } else { marginalizedVariableValue = assignment_1[i_2]; } } result.SetAssignmentLogValue(resultAssignment, curriedFoldr.Apply(marginalizedVariableValue, resultAssignment).Apply(result.GetAssignmentLogValue(resultAssignment), GetAssignmentLogValue(assignment_1))); if (fastPassByReferenceIterator.MoveNext()) { fastPassByReferenceIterator.Current; } else { break; } } return(result); }
/// <summary> /// Adds the sack step to this <see cref="GraphTraversal{SType, EType}"/>. /// </summary> public static ISchemaBoundTraversal <S, E> Sack <S, E>(this ISchemaBoundTraversal <S, E> traversal, IBiFunction sackOperator) { return(traversal.AsGraphTraversal().Sack(sackOperator).AsSchemaBound()); }