public PatternDetector(PatternDetector patternDetector) { lock (patternDetector) { DFAMatrix = patternDetector.DFAMatrix; } }
public PatternDetector(PatternCollection patterns) { PatternCollection = patterns; DFAMatrixBuilder lDFAMatrixBuilder = new DFAMatrixBuilder(patterns); DFAMatrix = lDFAMatrixBuilder.GetMatrix(); }
public void Add(DFAMatrix dfaMatrix) { if (dfaMatrix != null) { DFAMatrixes.Push(dfaMatrix); } }
protected void Merge(DFAMatrix dfaMatrixA, DFAMatrix dfaMatrixB, DFAMatrix dfaMatrixC) { DFANodes = new List <DFANode>(Compare.Max <int>(dfaMatrixA.DFANodes.Count, dfaMatrixB.DFANodes.Count, dfaMatrixC.DFANodes.Count) + 128); DFANodes.Add(new DFANode()); DFANodes.Add(new DFANode()); DFAMatrixCache3 cache = new DFAMatrixCache3(DFANodes.Capacity); Product(dfaMatrixA, 1, dfaMatrixB, 1, dfaMatrixC, 1, cache); }
public int GetPatterns(int state, char value, List <PatternKey> patternList) { if (DFANodes[state].Attributes != null) { foreach (PatternKey lPattern in DFANodes[state].Attributes) { patternList.Add(lPattern); } } return(DFANodes[state][DFAMatrix.GetDestination(value)]); }
public int GetPatterns(int state, char value, IPatternAddInterface patternList, Coordinate origin, int location) { if (DFANodes[state].Attributes != null) { foreach (PatternKey lPattern in DFANodes[state].Attributes) { patternList.Add(lPattern.Pattern, lPattern.Transformation, origin, location); } } return(DFANodes[state][DFAMatrix.GetDestination(value)]); }
// temp. for testing static void LoadCompiledMatrix() { Console.WriteLine(DateTime.Now.ToString()); SimpleTimer lTimer = new SimpleTimer(); DFAMatrix lDFAMatrix = new DFAMatrix(@"Patterns/fuseki9.cdb"); Console.WriteLine(lDFAMatrix.DFANodes.Count); Console.WriteLine(lTimer.SecondsElapsed.ToString()); GC.Collect(); }
public void Add(PatternCollection patterns) { DFAMatrixBuilder lDFAMatrixBuilder = new DFAMatrixBuilder(DFAMatrix); lDFAMatrixBuilder.Add(patterns); PatternCollection.Add(patterns); DFAMatrix lDFAMatrix = lDFAMatrixBuilder.GetMatrix(); lock (this) { DFAMatrix = lDFAMatrix; } }
public DFAMatrix GetMatrix() { if (DFAMatrixes.Count == 0) { return(null); } if (DFAMatrixes.Count > 1) { BuildThreaded(); } DFAMatrix lDFAMatrix = DFAMatrixes.Pop(); DFAMatrixes.Push(lDFAMatrix); return(lDFAMatrix); }
protected void Product(DFAMatrix dfaLeft, int left, DFAMatrix dfaRight, int right, DFAMatrixCache cache) { int lState = DFANodes.Count - 1; AttributeUnion(DFANodes[lState], dfaLeft.DFANodes[left], dfaRight.DFANodes[right]); for (int c = 0; c != 4; c++) { int lNextL = dfaLeft.DFANodes[left][c]; int lNextR = dfaRight.DFANodes[right][c]; if ((lNextL != 0) || (lNextR != 0)) { int lNewValue = cache.Search(lNextL, lNextR); if (lNewValue == 0) { // create it int lLastState = DFANodes.Count; //DFANodes.Add(new DFANode(DFANodes[lState].Level + 1)); DFANodes.Add(new DFANode()); cache.Add(lNextL, lNextR, lLastState); DFANodes[lState][c] = lLastState; Product(dfaLeft, lNextL, dfaRight, lNextR, cache); } else { // link to it DFANodes[lState][c] = lNewValue; } } else { DFANodes[lState][c] = 0; } } }
public DFAMatrix(DFAMatrix dfaMatrixA, DFAMatrix dfaMatrixB, DFAMatrix dfaMatrixC) { Merge(dfaMatrixA, dfaMatrixB, dfaMatrixC); }
public DFAMatrixBuilder(DFAMatrix dfaMatrix) { DFAMatrixes = new Stack <DFAMatrix>(); Add(dfaMatrix); }
public void Add(DFAMatrix dfaMatrix) { if (dfaMatrix != null) DFAMatrixes.Push(dfaMatrix); }
public DFAMatrixBuilder(DFAMatrix dfaMatrix) { DFAMatrixes = new Stack<DFAMatrix>(); Add(dfaMatrix); }
protected void Merge(DFAMatrix dfaMatrixA, DFAMatrix dfaMatrixB, DFAMatrix dfaMatrixC) { DFANodes = new List<DFANode>(Compare.Max<int>(dfaMatrixA.DFANodes.Count, dfaMatrixB.DFANodes.Count, dfaMatrixC.DFANodes.Count) + 128); DFANodes.Add(new DFANode()); DFANodes.Add(new DFANode()); DFAMatrixCache3 cache = new DFAMatrixCache3(DFANodes.Capacity); Product(dfaMatrixA, 1, dfaMatrixB, 1, dfaMatrixC, 1, cache); }
protected void Product(DFAMatrix dfaLeft, int left, DFAMatrix dfaMiddle, int middle, DFAMatrix dfaRight, int right, DFAMatrixCache3 cache) { int lState = DFANodes.Count - 1; AttributeUnion(DFANodes[lState], dfaLeft.DFANodes[left], dfaMiddle.DFANodes[middle], dfaRight.DFANodes[right]); for (int c = 0; c != 4; c++) { int lNextL = dfaLeft.DFANodes[left][c]; int lNextM = dfaMiddle.DFANodes[middle][c]; int lNextR = dfaRight.DFANodes[right][c]; if ((lNextL != 0) || (lNextM != 0) || (lNextR != 0)) { int lNewValue = cache.Search(lNextL, lNextM, lNextR); if (lNewValue == 0) { // create it int lLastState = DFANodes.Count; DFANodes.Add(new DFANode()); cache.Add(lNextL, lNextM, lNextR, lLastState); DFANodes[lState][c] = lLastState; Product(dfaLeft, lNextL, dfaMiddle, lNextM, dfaRight, lNextR, cache); } else { // link to it DFANodes[lState][c] = lNewValue; } } else { DFANodes[lState][c] = 0; } } }
public DFAMatrix(DFAMatrix dfaMatrixA, DFAMatrix dfaMatrixB) { Merge(dfaMatrixA, dfaMatrixB); }