Пример #1
0
        /// <summary>
        /// Loads an entry from a binary stream.
        /// </summary>
        public static EntryToken Load(BinaryReader reader, GrammarEngine engine)
        {
            int    id      = reader.ReadInt32();
            string srcWord = reader.ReadString();

            return(new EntryToken(engine.GetEntry(id), srcWord));
        }
Пример #2
0
 public PorjectionsEnumerator(GrammarEngine engine, IntPtr hList, int count)
 {
     _hList  = hList;
     _count  = count;
     _engine = engine;
     _cur    = -1;
 }
        internal WordProjection(GrammarEngine engine, IntPtr hList, int idx)
        {
            _engine = engine;
            _hList  = hList;
            _idx    = idx;

            Entry = _engine.GetEntry(GrammarApi.sol_GetIEntry(_hList, _idx));
        }
        /// <summary>
        /// Gets an instance of <see cref="GrammarEngine"/>. If there is
        /// no free object, creates a new one.
        /// </summary>
        /// <returns>Instance of GrammarEngine.</returns>
        public GrammarEngine GetInstance()
        {
            if (!_engines.TryDequeue(out var engine))
            {
                lock (_locker)
                {
                    if (!_engines.TryDequeue(out engine))
                    {
                        engine = new GrammarEngine(_dictPath);
                    }
                }
            }

            return(engine);
        }
        public SyntaxTreeNode(GrammarEngine gren, IntPtr hNode)
        {
            _gren  = gren;
            _hNode = hNode;

            Entry      = gren.GetEntry(GrammarApi.sol_GetNodeIEntry(_gren.GetEngineHandle(), _hNode));
            SourceWord = GetNodeContents(_hNode);

            int nleaf = GrammarApi.sol_CountLeafs(_hNode);

            Leafs = new SyntaxTreeNode[nleaf];
            for (int i = 0; i < nleaf; ++i)
            {
                Leafs[i] = new SyntaxTreeNode(_gren, GrammarApi.sol_GetLeaf(_hNode, i));
            }
        }
        public AnalysisResults(GrammarEngine gren, IntPtr hPack, bool preserveMarkers = false)
        {
            _hPack = hPack;

            int n = GrammarApi.sol_CountRoots(_hPack, 0);

            if (n == 0)
            {
                _nodes = new SyntaxTreeNode[0];
                return;
            }

            int offset = preserveMarkers ? 0 : 1;

            _nodes = new SyntaxTreeNode[n - offset * 2];
            for (int i = offset; i < n - offset; i++)
            {
                _nodes[i - offset] = new SyntaxTreeNode(gren, GrammarApi.sol_GetRoot(_hPack, 0, i));
            }
        }
 /// <summary>
 /// Returns an instance of GrammarEngine to the pool.
 /// </summary>
 /// <param name="engine">Engine to return.</param>
 public void ReturnInstance(GrammarEngine engine)
 {
     _engines.Enqueue(engine);
 }
Пример #8
0
 public ProjectionResults(GrammarEngine engine, IntPtr hList)
 {
     _engine = engine;
     _hList  = hList;
 }