将文本文件加载到文本引擎中

时间:2018-12-05 22:14:35

标签: java

    public void loadContent(String content, Set<Character> punctuationSet) throws AnalyzableException {
    String current = "";
    if(content == null || punctuationSet == null) {
        throw new AnalyzableException("bad data foo");
    } 
    words = new ArrayList<>();
    for(int pos = 0; pos < content.length(); pos++){
        if(punctuationSet.contains(content.charAt(pos))) {
            } else {
                current += content.charAt(pos);
                words.add(new Word (current, pos, pos, pos, pos));
            }
        }
    }

该程序是一个文本引擎,应该使用此方法将内容加载到程序中。 “单词”是指存储所有单词的对象列表。

 content = "\tAddress Delivered at the Dedication of the Cemetery at Gettysburg\n" + "\tAbraham Lincoln\n"
            + "\tNovember 19, 1863";
    Set<Character> pset = new HashSet<>(Arrays.asList(',', '.'));

    System.out.println("Setting content to the following String:");
    System.out.println(content);

    ///*************************************************
    ///************ Test Analyzable ********************
    ///*************************************************
    System.out.println("Testing Analyzable");        
    Accessible accKernel = factory.generateAccessibleKernel();
    try {
        accKernel.loadContent(content, pset);
    } catch (AnalyzableException e) {
        System.out.println("Exception throwing while loading content.");
        e.printStackTrace();
    }

    /* Test 4: Analyzable.getRawContent() */
    System.out.print("\tTest 4: Analyzable.getRawContent() ");
    if(content.equals(accKernel.getRawContent()))
    {
        System.out.println("Passed");
        countPassed++;
    }
    else
    {
        System.out.println("Failed. \"Expected: " + content);
        System.out.println("Accessible.getRawContent() returned: " + accKernel.getRawContent());
    }

这是提供给我们的程序,用于测试我们的程序,每当调用另一个引用回loadContent方法的方法时,我都无法通过测试。因此,我认为我的loadContent方法存在问题,我无法弄清楚它是什么。

0 个答案:

没有答案
相关问题