All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pingbu.nlp.SubtreeSlot Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package pingbu.nlp;

/**
 * 语法槽子树,对下级子树产生槽信息
 * 
 * @author pingbu
 */
class SubtreeSlot extends Subtree {

    private final String mName;
    private final Subtree mSubtree;

    public SubtreeSlot(String name, Subtree subtree) {
        mName = name;
        mSubtree = subtree;
    }

    private class EnterCursor extends Cursor {

        public EnterCursor(Cursor returnCursor) {
            super(returnCursor);
        }

        @Override
        public void navigate(Navigator navigator) {
            mSubtree.newCursor(
                    new ExitCursor(mReturnCursor, navigator.beginSlot()))
                    .navigate(navigator);
        }

        private class ExitCursor extends Cursor {

            private Object mBeginPos;

            public ExitCursor(Cursor returnCursor, Object beginPos) {
                super(returnCursor);
                mBeginPos = beginPos;
            }

            @Override
            public void navigate(Navigator navigator) {
                navigator.pushSlot(mName, mBeginPos);
                navigateReturn(navigator);
                navigator.popSlot();
            }
        }
    }

    @Override
    public Cursor newCursor(Cursor returnCursor) {
        return new EnterCursor(returnCursor);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy