⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atomparsertest.java

📁 该原代码是实现机器学习中条件随机场模型的Java代码
💻 JAVA
字号:
package lcrf.logic;

import java.io.StringReader;
import java.util.Vector;

import junit.framework.TestCase;
import lcrf.logic.parser.AtomParser;

public class AtomParserTest extends TestCase {
    public void testConstant() throws Exception {

        AtomParser parser = new AtomParser(new StringReader(" dog  (  A )"));
        Term t_parsed = parser.Term();
        Vector<Term> subterms = new Vector<Term>();
        subterms.add(new Variable("A"));
        Constant t_constructed = new Constant("dog", subterms);
        assertEquals(t_constructed, t_parsed);
    }

    public void testConstant2() throws Exception {
        AtomParser parser = new AtomParser(new StringReader("a(  a(b))"));
        Term t_parsed = parser.Term();
        Vector<Term> subterms = new Vector<Term>();
        subterms.add(new Constant("b", new Vector<Term>()));
        Vector<Term> subterms2 = new Vector<Term>();
        subterms2.add(new Constant("a", subterms));

        Constant t_constructed = new Constant("a", subterms2);
        assertEquals(t_constructed, t_parsed);

    }

    public void testConstant3() throws Exception {
        AtomParser parser = new AtomParser(new StringReader("a(  a(b,'hello'), 42)"));
        Term t_parsed = parser.Term();

        Vector<Term> subterms = new Vector<Term>();
        subterms.add(new Constant("b"));
        subterms.add(new StringConstant("hello"));

        Vector<Term> subterms2 = new Vector<Term>();
        subterms2.add(new Constant("a", subterms));
        subterms2.add(new NumberConstant(42));

        Constant t_constructed = new Constant("a", subterms2);
        assertEquals(t_constructed, t_parsed);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -