Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package paczka;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Scanner;
- class WordForm {
- private String dictionaryForm;
- private String[] forms;
- public WordForm(String data) {
- data.trim();
- forms = data.split(",");
- dictionaryForm = forms[0];
- }
- public String getDictionaryForm() { return dictionaryForm; }
- public int getNumberOfForms() { return forms.length-1; }
- public String getForm(int i) {
- if(i < 0 || i > getNumberOfForms())
- return "";
- return forms[i];
- }
- }
- class Main {
- public static void main(String[] args) {
- ArrayList<WordForm> wordForms = new ArrayList<>();
- File file = new File("dictionary.txt");
- try {
- Scanner scanner = new Scanner(file);
- StringBuilder line = new StringBuilder();
- while(scanner.hasNext()) {
- line.append(scanner.nextLine());
- if(line.toString().contains("^M")) {
- line.delete(line.length() - 2, line.length());
- wordForms.add(new WordForm(line.toString()));
- line.delete(0, line.length());
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- WordForm wordForm = wordForms.get(55);
- System.out.println("word: " + wordForm.getDictionaryForm());
- System.out.println("number of forms: " + wordForm.getNumberOfForms());
- for(int i = 1; i < wordForm.getNumberOfForms(); i++) {
- System.out.println(i + " " + wordForm.getForm(i));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement