Разбор файлов MealMaster в Java - PullRequest
0 голосов
/ 17 декабря 2018

В настоящее время я пытаюсь выполнить синтаксический анализ файлов MealMaster, но у меня возникла проблема, при которой ингредиенты анализируются как:

  • "Толщина в дюймах" из-за следующей строкине имея количества или единицы и продолжая предыдущее

  • Кроме того, я нахожу ингредиенты, которые перечислены как «ингредиент1 или ингредиент2», и я не знаю, как их разлагатьэто в парсере

Вот пример файла, из которого я разбираю код, и мой код ниже https://pastebin.com/fhkRczya

public void readIngredients() {
    try {
        Remover remover = new Remover();
        ArrayList<Ingredient> ing = new ArrayList<Ingredient>();
        while(!( "".equals(line.trim()))) {
            parsedIngredients = line + "\n";
            if(!line.contains("---") && !line.contains(":")) {
                Ingredient currentIng = splitLine();
                if(currentIng.getQuantity().length() == 0 && !ing.isEmpty()) {
                    Ingredient lastIng = ing.get(ing.size()-1);
                    if (currentIng.getName().toLowerCase().contains("inch") ) {
                        //System.out.println(currentIng.getName());
                        lastIng.setOther(lastIng.getOther() + "," + currentIng.getQuantity() + ","  +currentIng.getName());
                        //System.out.println("OTher       " + lastIng.getOther());
                    }else{
                        String lastIngName = lastIng.getName();
                        String addName = lastIngName + " " + currentIng.getName();
                        lastIng.setName(addName);
                        lastIng = remover.removeTo(unitWords,lastIng);
                        lastIng = remover.removeCustomWords(lastIng);
                    }
                }else if (currentIng.getName().startsWith("-") || currentIng.getName().startsWith("For") ){
                    if(ing.size()>0) {
                    Ingredient lastIng = ing.get(ing.size()-1);
                    lastIng.setOther(currentIng.getQuantity() + " " + currentIng.getName());
                    }
                }else {

                    currentIng = remover.removeTo(unitWords,currentIng);
                    currentIng = remover.removeCustomWords(currentIng);
                    //currentIng.setName(currentIng.getName().replace(",", ""));

                    System.out.println(currentIng.getName());
                    ing.add(currentIng);
                }
            }


            line = reader.readLine();


        }

        for(int i = 0; i < ing.size();i++) {
            removeCommaColon(ing.get(i));
        }

        for(int i = 0; i<ing.size();i++) {
            ingredientsString = ingredientsString + ing.get(i).getName() + "|" + currentRecipe.getTitle() + " \n";
            //ingredientsString = ingredientsString + currentRecipe.getTitle() + "\n";
        }

        currentRecipe.setIngredients(ing);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
...