1. Vadim Ne.
  2. internship

Commits

Vadim Ne.  committed 5d97b1d

Task 3. Refactored amount of packages and some class movements.

  • Participants
  • Parent commits 0932562
  • Branches master

Comments (0)

Files changed (121)

File database-services-api/src/main/java/databaseServicesApi/DatabaseAdderInterface.java

View file
+package databaseServicesApi;
+
+import libngram.PhraseDataHolder;
+
+import java.sql.SQLException;
+
+public interface DatabaseAdderInterface {
+    void addToDatabase(PhraseDataHolder data) throws Exception;
+
+    void closeDatabaseConnection() throws SQLException;
+}

File database-services-api/src/main/java/databaseServicesApi/NgramDto.java

View file
+package databaseServicesApi;
+
+/**
+ * It's supposed that object gets validated data. Object doesn't do validation.
+ */
+public class NgramDto {
+    private final String data;
+    private final int count;
+
+    public NgramDto(String data, int count) {
+        this.data = data;
+        this.count = count;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public int getCount() {
+        return count;
+    }
+}

File database-services-api/src/main/java/databaseServicesApi/NgramsDatabaseReaderInterface.java

View file
+package databaseServicesApi;
+
+import java.util.List;
+
+public interface NgramsDatabaseReaderInterface {
+    NgramDto searchNgramByDataFullMatch(String ngramData);
+
+    List<NgramDto> getListOfNgrams(NgramsListQueryObject ngramsListQuery);
+
+    int getAmountOfNgramsInDatabase();
+}

File database-services-api/src/main/java/databaseServicesApi/NgramsListQueryObject.java

View file
+package databaseServicesApi;
+
+public class NgramsListQueryObject {
+    public static class NgramsListQueryBuilder {
+        //required
+        private int amount;
+        private int offsetPage;
+
+        //optional
+        private String orderByFieldNameString;
+        private NgramsSortFieldName orderByFieldName;
+        private String orderString;
+        private Order order;
+
+        public NgramsListQueryBuilder(int amount, int offsetPage) {
+            this.amount = amount;
+            this.offsetPage = offsetPage;
+        }
+
+        public NgramsListQueryBuilder orderByField(Enum fieldName) {
+            if (fieldName == null)
+                this.orderByFieldNameString = "";
+            else
+                this.orderByFieldNameString = fieldName.name();
+            return this;
+        }
+
+        public NgramsListQueryBuilder order(Enum order) {
+            if (order == null)
+                this.orderString = "";
+            else
+                this.orderString = order.name();
+            return this;
+        }
+
+        public NgramsListQueryObject build() throws QueryObjectBuilderValidationError {
+            if (amount < 1) {
+                throw new QueryObjectBuilderValidationError("Amount of items in list is negative or zero.");
+            }
+
+            if (offsetPage < 0) {
+                throw new QueryObjectBuilderValidationError("Offset page number is negative.");
+            }
+
+            try {
+                orderByFieldName = NgramsSortFieldName.valueOf(orderByFieldNameString);
+            } catch (Exception e) {
+                orderByFieldName = null;
+                //throw new QueryObjectBuilderValidationError("Field name to order is incorrect.");
+            }
+
+            try {
+                order = Order.valueOf(orderString);
+            } catch (Exception e) {
+                order = null;
+                //throw new QueryObjectBuilderValidationError("Order tag is incorrect.");
+            }
+
+            return new NgramsListQueryObject(this);
+        }
+    }
+
+    //required
+    private final int amount;
+    private final int offsetPage;
+
+    //optional
+    private final NgramsSortFieldName orderByFieldName;
+    private final Order order;
+
+    private NgramsListQueryObject(NgramsListQueryBuilder ngramsListQueryBuilder) {
+        this.amount = ngramsListQueryBuilder.amount;
+        this.offsetPage = ngramsListQueryBuilder.offsetPage;
+        this.orderByFieldName = ngramsListQueryBuilder.orderByFieldName;
+        this.order = ngramsListQueryBuilder.order;
+    }
+
+    public int getAmount() {
+        return amount;
+    }
+
+    public int getOffsetPage() {
+        return offsetPage;
+    }
+
+    public NgramsSortFieldName getOrderByFieldName() {
+        return orderByFieldName;
+    }
+
+    public Order getOrder() {
+        return order;
+    }
+}

File database-services-api/src/main/java/databaseServicesApi/NgramsSortFieldName.java

View file
+package databaseServicesApi;
+
+public enum NgramsSortFieldName {
+    name, count
+}

File database-services-api/src/main/java/databaseServicesApi/Order.java

View file
+package databaseServicesApi;
+
+public enum Order {
+    asc, desc
+}

File database-services-api/src/main/java/databaseServicesApi/QueryObjectBuilderValidationError.java

View file
+package databaseServicesApi;
+
+public class QueryObjectBuilderValidationError extends Exception {
+    public QueryObjectBuilderValidationError(String message) {
+        super(message);
+    }
+}

File database-services-api/src/main/java/databaseServicesApi/WordForNgramWithCountDto.java

View file
+package databaseServicesApi;
+
+/**
+ * It's supposed that object gets validated data. Object doesn't do validation.
+ */
+public class WordForNgramWithCountDto {
+    private final String word;
+    private final int count;
+
+    public WordForNgramWithCountDto(String word, int count) {
+        this.word = word;
+        this.count = count;
+    }
+
+    public String getWord() {
+        return word;
+    }
+
+    public int getCount() {
+        return count;
+    }
+}

File database-services-api/src/main/java/databaseServicesApi/WordsDatabaseReaderInterface.java

View file
+package databaseServicesApi;
+
+import java.util.List;
+
+public interface WordsDatabaseReaderInterface {
+    List<WordForNgramWithCountDto> getListOfWordsWithCounters(WordsListQueryObject wordsListQuery);
+
+    int getAmountOfWordsWithCountersInDatabase(String ngramData, String partOfWord);
+}

File database-services-api/src/main/java/databaseServicesApi/WordsListQueryObject.java

View file
+package databaseServicesApi;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class WordsListQueryObject {
+    public static class WordsListQueryBuilder {
+        //required
+        private String ngramData;
+        private int amountOfElements;
+        private int offsetPage;
+        private String wordToSearchPattern;
+
+        //optional
+        private String orderByFieldNameString;
+        private WordsSortFieldName orderByFieldName;
+        private String orderString;
+        private Order order;
+
+        public WordsListQueryBuilder(String ngramData, int amountOfElements, int offsetPage, String wordToSearchPattern) {
+            this.ngramData = ngramData;
+            this.amountOfElements = amountOfElements;
+            this.offsetPage = offsetPage;
+            this.wordToSearchPattern = wordToSearchPattern;
+        }
+
+        public WordsListQueryBuilder orderByField(Enum fieldName) {
+            if (fieldName == null)
+                this.orderByFieldNameString = "";
+            else
+                this.orderByFieldNameString = fieldName.name();
+            return this;
+        }
+
+        public WordsListQueryBuilder order(Enum order) {
+            if (order == null)
+                this.orderString = "";
+            else
+                this.orderString = order.name();
+            return this;
+        }
+
+        public WordsListQueryObject build() throws QueryObjectBuilderValidationError {
+            if (StringUtils.isEmpty(ngramData)) {
+                throw new QueryObjectBuilderValidationError("N-gram data is not defined.");
+            }
+
+            if (amountOfElements < 1) {
+                throw new QueryObjectBuilderValidationError("Amount of items in list is negative or zero.");
+            }
+
+            if (offsetPage < 0) {
+                throw new QueryObjectBuilderValidationError("Offset page number is negative.");
+            }
+
+            if (StringUtils.isEmpty(wordToSearchPattern)) {
+                throw new QueryObjectBuilderValidationError("Word search pattern is null or empty.");
+            }
+
+            try {
+                orderByFieldName = WordsSortFieldName.valueOf(orderByFieldNameString);
+            } catch (Exception e) {
+                orderByFieldName = null;
+                //throw new QueryObjectBuilderValidationError("Field name to order is incorrect.");
+            }
+
+            try {
+                order = Order.valueOf(orderString);
+            } catch (Exception e) {
+                order = null;
+                //throw new QueryObjectBuilderValidationError("Order tag is incorrect.");
+            }
+
+            return new WordsListQueryObject(this);
+        }
+    }
+
+    //required
+    private final int amountOfElements;
+    private final int offsetPage;
+    private String ngramData;
+    private String wordToSearchPattern;
+
+    //optional
+    private final WordsSortFieldName orderByFieldName;
+    private final Order order;
+
+    private WordsListQueryObject(WordsListQueryBuilder wordsListQueryBuilder) {
+        this.amountOfElements = wordsListQueryBuilder.amountOfElements;
+        this.offsetPage = wordsListQueryBuilder.offsetPage;
+        this.ngramData = wordsListQueryBuilder.ngramData;
+        this.wordToSearchPattern = wordsListQueryBuilder.wordToSearchPattern;
+        this.orderByFieldName = wordsListQueryBuilder.orderByFieldName;
+        this.order = wordsListQueryBuilder.order;
+    }
+
+    public int getAmountOfElements() {
+        return amountOfElements;
+    }
+
+    public int getOffsetPage() {
+        return offsetPage;
+    }
+
+    public String getNgramData() {
+        return ngramData;
+    }
+
+    public String getWordToSearchPattern() {
+        return wordToSearchPattern;
+    }
+
+    public WordsSortFieldName getOrderByFieldName() {
+        return orderByFieldName;
+    }
+
+    public Order getOrder() {
+        return order;
+    }
+}

File database-services-api/src/main/java/databaseServicesApi/WordsSortFieldName.java

View file
+package databaseServicesApi;
+
+public enum WordsSortFieldName {
+    word, count
+}

File database-services-api/src/main/java/dtConverters/NgramsListDaoToDto.java

-package dtConverters;
-
-import dtObjects.Ngram;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class NgramsListDaoToDto {
-    public static List<Ngram> convert(List<dao.entities.dbTables.Ngram> listToConvert) {
-        List<Ngram> listToReturn = new ArrayList<Ngram>();
-        for (dao.entities.dbTables.Ngram element : listToConvert) {
-            listToReturn.add(new Ngram(element.getData(), element.getCount()));
-        }
-
-        return listToReturn;
-    }
-}

File database-services-api/src/main/java/dtConverters/WordsListDaoToDto.java

-package dtConverters;
-
-import dtObjects.WordForNgramWithCount;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class WordsListDaoToDto {
-    public static List<WordForNgramWithCount> convert(List<dao.entities.logical.WordForNgramWithCount> listToConvert) {
-        List<WordForNgramWithCount> listToReturn = new ArrayList<WordForNgramWithCount>();
-        for (dao.entities.logical.WordForNgramWithCount element : listToConvert) {
-            listToReturn.add(new WordForNgramWithCount(element.getWord(), element.getCount()));
-        }
-
-        return listToReturn;
-    }
-}

File database-services-api/src/main/java/dtObjects/Ngram.java

-package dtObjects;
-
-/**
- * It's supposed that object gets validated data. Object doesn't do validation.
- */
-public class Ngram {
-    private final String data;
-    private final int count;
-
-    public Ngram(String data, int count) {
-        this.data = data;
-        this.count = count;
-    }
-
-    public String getData() {
-        return data;
-    }
-
-    public int getCount() {
-        return count;
-    }
-}

File database-services-api/src/main/java/dtObjects/WordForNgramWithCount.java

-package dtObjects;
-
-/**
- * It's supposed that object gets validated data. Object doesn't do validation.
- */
-public class WordForNgramWithCount {
-    private final String word;
-    private final int count;
-
-    public WordForNgramWithCount(String word, int count) {
-        this.word = word;
-        this.count = count;
-    }
-
-    public String getWord() {
-        return word;
-    }
-
-    public int getCount() {
-        return count;
-    }
-}

File database-services-api/src/main/java/queryConverters/NgramsListQueryObjectToDaoQueryObjectConverter.java

-package queryConverters;
-
-import dao.daoQueryObjects.NgramsListDaoQueryObject;
-import queryObjects.NgramsListQueryObject;
-
-public class NgramsListQueryObjectToDaoQueryObjectConverter {
-    public static NgramsListDaoQueryObject convert(NgramsListQueryObject ngramsListQuery) {
-        return new NgramsListDaoQueryObject(
-                ngramsListQuery.getAmount(),
-                ngramsListQuery.getOffsetPage(),
-                ngramsListQuery.getOrderByFieldName(),
-                ngramsListQuery.getOrder());
-    }
-}

File database-services-api/src/main/java/queryConverters/WordsListQueryObjectToDaoQueryObjectConverter.java

-package queryConverters;
-
-import dao.daoQueryObjects.WordsListDaoQueryObject;
-import queryObjects.WordsListQueryObject;
-
-public class WordsListQueryObjectToDaoQueryObjectConverter {
-    public static WordsListDaoQueryObject convert(int ngramId, WordsListQueryObject wordsListQuery) {
-        return new WordsListDaoQueryObject(ngramId,
-                wordsListQuery.getOffsetPage(),
-                wordsListQuery.getAmountOfElements(),
-                wordsListQuery.getWordToSearchPattern(),
-                wordsListQuery.getOrderByFieldName(),
-                wordsListQuery.getOrder());
-    }
-}

File database-services-api/src/main/java/queryObjects/NgramsListQueryObject.java

-package queryObjects;
-
-import queryOptions.NgramsSortFieldName;
-import queryOptions.Order;
-
-public class NgramsListQueryObject {
-    public static class NgramsListQueryBuilder {
-        //required
-        private int amount;
-        private int offsetPage;
-
-        //optional
-        private String orderByFieldNameString;
-        private NgramsSortFieldName orderByFieldName;
-        private String orderString;
-        private Order order;
-
-        public NgramsListQueryBuilder(int amount, int offsetPage) {
-            this.amount = amount;
-            this.offsetPage = offsetPage;
-        }
-
-        public NgramsListQueryBuilder orderByField(Enum fieldName) {
-            if (fieldName == null)
-                this.orderByFieldNameString = "";
-            else
-                this.orderByFieldNameString = fieldName.name();
-            return this;
-        }
-
-        public NgramsListQueryBuilder order(Enum order) {
-            if (order == null)
-                this.orderString = "";
-            else
-                this.orderString = order.name();
-            return this;
-        }
-
-        public NgramsListQueryObject build() throws QueryObjectBuilderValidationError {
-            if (amount < 1) {
-                throw new QueryObjectBuilderValidationError("Amount of items in list is negative or zero.");
-            }
-
-            if (offsetPage < 0) {
-                throw new QueryObjectBuilderValidationError("Offset page number is negative.");
-            }
-
-            try {
-                orderByFieldName = NgramsSortFieldName.valueOf(orderByFieldNameString);
-            } catch (Exception e) {
-                orderByFieldName = null;
-                //throw new QueryObjectBuilderValidationError("Field name to order is incorrect.");
-            }
-
-            try {
-                order = Order.valueOf(orderString);
-            } catch (Exception e) {
-                order = null;
-                //throw new QueryObjectBuilderValidationError("Order tag is incorrect.");
-            }
-
-            return new NgramsListQueryObject(this);
-        }
-    }
-
-    //required
-    private final int amount;
-    private final int offsetPage;
-
-    //optional
-    private final NgramsSortFieldName orderByFieldName;
-    private final Order order;
-
-    private NgramsListQueryObject(NgramsListQueryBuilder ngramsListQueryBuilder) {
-        this.amount = ngramsListQueryBuilder.amount;
-        this.offsetPage = ngramsListQueryBuilder.offsetPage;
-        this.orderByFieldName = ngramsListQueryBuilder.orderByFieldName;
-        this.order = ngramsListQueryBuilder.order;
-    }
-
-    public int getAmount() {
-        return amount;
-    }
-
-    public int getOffsetPage() {
-        return offsetPage;
-    }
-
-    public NgramsSortFieldName getOrderByFieldName() {
-        return orderByFieldName;
-    }
-
-    public Order getOrder() {
-        return order;
-    }
-}

File database-services-api/src/main/java/queryObjects/QueryObjectBuilderValidationError.java

-package queryObjects;
-
-public class QueryObjectBuilderValidationError extends Exception {
-    public QueryObjectBuilderValidationError(String message) {
-        super(message);
-    }
-}

File database-services-api/src/main/java/queryObjects/WordsListQueryObject.java

-package queryObjects;
-
-import org.apache.commons.lang3.StringUtils;
-import queryOptions.Order;
-import queryOptions.WordsSortFieldName;
-
-public class WordsListQueryObject {
-    public static class WordsListQueryBuilder {
-        //required
-        private String ngramData;
-        private int amountOfElements;
-        private int offsetPage;
-        private String wordToSearchPattern;
-
-        //optional
-        private String orderByFieldNameString;
-        private WordsSortFieldName orderByFieldName;
-        private String orderString;
-        private Order order;
-
-        public WordsListQueryBuilder(String ngramData, int amountOfElements, int offsetPage, String wordToSearchPattern) {
-            this.ngramData = ngramData;
-            this.amountOfElements = amountOfElements;
-            this.offsetPage = offsetPage;
-            this.wordToSearchPattern = wordToSearchPattern;
-        }
-
-        public WordsListQueryBuilder orderByField(Enum fieldName) {
-            if (fieldName == null)
-                this.orderByFieldNameString = "";
-            else
-                this.orderByFieldNameString = fieldName.name();
-            return this;
-        }
-
-        public WordsListQueryBuilder order(Enum order) {
-            if (order == null)
-                this.orderString = "";
-            else
-                this.orderString = order.name();
-            return this;
-        }
-
-        public WordsListQueryObject build() throws QueryObjectBuilderValidationError {
-            if (StringUtils.isEmpty(ngramData)) {
-                throw new QueryObjectBuilderValidationError("N-gram data is not defined.");
-            }
-
-            if (amountOfElements < 1) {
-                throw new QueryObjectBuilderValidationError("Amount of items in list is negative or zero.");
-            }
-
-            if (offsetPage < 0) {
-                throw new QueryObjectBuilderValidationError("Offset page number is negative.");
-            }
-
-            if (StringUtils.isEmpty(wordToSearchPattern)) {
-                throw new QueryObjectBuilderValidationError("Word search pattern is null or empty.");
-            }
-
-            try {
-                orderByFieldName = WordsSortFieldName.valueOf(orderByFieldNameString);
-            } catch (Exception e) {
-                orderByFieldName = null;
-                //throw new QueryObjectBuilderValidationError("Field name to order is incorrect.");
-            }
-
-            try {
-                order = Order.valueOf(orderString);
-            } catch (Exception e) {
-                order = null;
-                //throw new QueryObjectBuilderValidationError("Order tag is incorrect.");
-            }
-
-            return new WordsListQueryObject(this);
-        }
-    }
-
-    //required
-    private final int amountOfElements;
-    private final int offsetPage;
-    private String ngramData;
-    private String wordToSearchPattern;
-
-    //optional
-    private final WordsSortFieldName orderByFieldName;
-    private final Order order;
-
-    private WordsListQueryObject(WordsListQueryBuilder wordsListQueryBuilder) {
-        this.amountOfElements = wordsListQueryBuilder.amountOfElements;
-        this.offsetPage = wordsListQueryBuilder.offsetPage;
-        this.ngramData = wordsListQueryBuilder.ngramData;
-        this.wordToSearchPattern = wordsListQueryBuilder.wordToSearchPattern;
-        this.orderByFieldName = wordsListQueryBuilder.orderByFieldName;
-        this.order = wordsListQueryBuilder.order;
-    }
-
-    public int getAmountOfElements() {
-        return amountOfElements;
-    }
-
-    public int getOffsetPage() {
-        return offsetPage;
-    }
-
-    public String getNgramData() {
-        return ngramData;
-    }
-
-    public String getWordToSearchPattern() {
-        return wordToSearchPattern;
-    }
-
-    public WordsSortFieldName getOrderByFieldName() {
-        return orderByFieldName;
-    }
-
-    public Order getOrder() {
-        return order;
-    }
-}

File database-services-api/src/main/java/queryOptions/NgramsSortFieldName.java

-package queryOptions;
-
-public enum NgramsSortFieldName {
-    name, count
-}

File database-services-api/src/main/java/queryOptions/Order.java

-package queryOptions;
-
-public enum Order {
-    asc, desc
-}

File database-services-api/src/main/java/queryOptions/WordsSortFieldName.java

-package queryOptions;
-
-public enum WordsSortFieldName {
-    word, count
-}

File database-services-api/src/main/java/services/DatabaseAdderInterface.java

-package services;
-
-import dataStructures.PhraseDataHolder;
-
-import java.sql.SQLException;
-
-public interface DatabaseAdderInterface {
-    void addToDatabase(PhraseDataHolder data) throws Exception;
-
-    void closeDatabaseConnection() throws SQLException;
-}

File database-services-api/src/main/java/services/NgramsDatabaseReaderInterface.java

-package services;
-
-import dtObjects.Ngram;
-import queryObjects.NgramsListQueryObject;
-
-import java.util.List;
-
-public interface NgramsDatabaseReaderInterface {
-    Ngram searchNgramByDataFullMatch(String ngramData);
-
-    List<Ngram> getListOfNgrams(NgramsListQueryObject ngramsListQuery);
-
-    int getAmountOfNgramsInDatabase();
-}

File database-services-api/src/main/java/services/WordsDatabaseReaderInterface.java

-package services;
-
-import dtObjects.WordForNgramWithCount;
-import queryObjects.WordsListQueryObject;
-
-import java.util.List;
-
-public interface WordsDatabaseReaderInterface {
-    List<WordForNgramWithCount> getListOfWordsWithCounters(WordsListQueryObject wordsListQuery);
-
-    int getAmountOfWordsWithCountersInDatabase(String ngramData, String partOfWord);
-}

File database-services-impl/src/main/java/databaseServicesImplementation/DatabaseAdder.java

View file
+package databaseServicesImplementation;
+
+import dao.*;
+import dao.entities.Ngram;
+import dao.entities.NgramToWord;
+import dao.entities.WordToPhrase;
+import dao.jdbcDao.IllegalInputSizeException;
+import dao.jdbcDao.*;
+import libngram.PhraseDataHolder;
+import libngram.WordWithNgrams;
+import databaseServicesApi.DatabaseAdderInterface;
+import jdbcUtilities.JdbcH2DataSource;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public class DatabaseAdder implements DatabaseAdderInterface {
+    private Connection connection;
+
+    private PhrasesDao phrasesDao;
+    private WordsDao wordsDao;
+    private NgramsDao ngramsDao;
+    private WordsToPhrasesDao wordsToPhrasesDao;
+    private NgramsToWordsDao ngramsToWordsDao;
+
+    public DatabaseAdder() throws SQLException {
+        connection = JdbcH2DataSource.getDBConnection();
+
+        connection.setAutoCommit(false);
+        connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+
+        phrasesDao = new JdbcPhrasesDao(connection);
+        wordsDao = new JdbcWordsDao(connection);
+        ngramsDao = new JdbcNgramsDao(connection);
+
+        wordsToPhrasesDao = new JdbcWordsToPhrasesDao(connection);
+        ngramsToWordsDao = new JdbcNgramsToWordsDao(connection);
+    }
+
+    public void clearDatabase() throws SQLException {
+        // Clear data in tables phase
+        ngramsToWordsDao.removeAllEntetiesFromTable();
+        wordsToPhrasesDao.removeAllEntetiesFromTable();
+        ngramsDao.removeAllEntetiesFromTable();
+        wordsDao.removeAllEntetiesFromTable();
+        phrasesDao.removeAllEntetiesFromTable();
+
+        connection.commit();
+    }
+
+    @Override
+    public void addToDatabase(PhraseDataHolder data) throws Exception {
+        try {
+            // Insert phrase into table
+            int phraseDbId = phrasesDao.insertNewPhrase(data.getPhrase());
+
+            // Insert Elements into table
+            for (WordWithNgrams wordWithNgrams : data.getWordsWithNgramsList()) {
+                String currentWordData = wordWithNgrams.getWord();
+
+                boolean isWordNew = false;
+
+                int wordDbId = wordsDao.findWord(currentWordData);
+                if (wordDbId == 0) {
+                    wordDbId = wordsDao.insertNewWord(currentWordData, phraseDbId);
+                    isWordNew = true;
+                }
+
+                WordToPhrase wordToPhrase = wordsToPhrasesDao.findWordToPhrase(wordDbId, phraseDbId);
+                if (wordToPhrase == null) {
+                    wordsToPhrasesDao.insertNewWordToPhrase(wordDbId, phraseDbId);
+                } else {
+                    wordToPhrase.incrementCounter();
+                    wordsToPhrasesDao.updateWordToPhraseCounter(wordToPhrase);
+                }
+
+                if (wordWithNgrams.getNgramsList() != null) {
+                    for (String currentNgramData : wordWithNgrams.getNgramsList()) {
+                        // Find and insert ngram into dbTables or increment ngram counter
+                        Ngram ngram = ngramsDao.findByDataString(currentNgramData);
+                        if (ngram == null) {
+                            int newNgramDbIndex = ngramsDao.insertNewNgram(currentNgramData);
+                            ngram = new Ngram(newNgramDbIndex, currentNgramData, 1);
+                        } else {
+                            ngram.incrementCounter();
+                            ngramsDao.updateNgramCounter(ngram);
+                        }
+
+                        // Find and insert ngram_to_word relation of increment ngram in word counter
+                        NgramToWord ngramToWord = ngramsToWordsDao.findNgramToWord(ngram.getId(), wordDbId);
+                        if (ngramToWord == null) {
+                            ngramsToWordsDao.insertNewNgramsToWords(ngram.getId(), wordDbId);
+                        } else {
+                            if (isWordNew) {
+                                ngramToWord.incrementCounter();
+                                ngramsToWordsDao.updateNgramToWordCounter(ngramToWord);
+                            }
+                        }
+                    }
+                    connection.commit();
+                }
+            }
+            connection.commit();
+        } catch (SQLException e) {
+            connection.rollback();
+            System.out.println(e.getMessage());
+        } catch (IllegalInputSizeException e) {
+            connection.rollback();
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public void closeDatabaseConnection() throws SQLException {
+        connection.close();
+    }
+
+    protected void finalize() throws Throwable {
+        try {
+            closeDatabaseConnection();
+        } finally {
+            super.finalize();
+        }
+    }
+}

File database-services-impl/src/main/java/databaseServicesImplementation/NgramsJdbcReader.java

View file
+package databaseServicesImplementation;
+
+import dao.NgramsDao;
+import dao.daoQueryObjects.NgramsListDaoQueryObject;
+import dao.entities.Ngram;
+import dao.jdbcDao.JdbcNgramsDao;
+import databaseServicesApi.NgramDto;
+import databaseServicesApi.NgramsDatabaseReaderInterface;
+import databaseServicesApi.NgramsListQueryObject;
+import jdbcUtilities.JdbcH2DataSource;
+
+import java.util.List;
+
+public class NgramsJdbcReader implements NgramsDatabaseReaderInterface {
+    private final NgramsDao ngramsDao;
+
+    public NgramsJdbcReader() {
+        ngramsDao = new JdbcNgramsDao(JdbcH2DataSource.getDBConnection());
+    }
+
+    @Override
+    public NgramDto searchNgramByDataFullMatch(String ngramData) {
+        Ngram ngram = ngramsDao.findByDataString(ngramData);
+        return new NgramDto(ngram.getData(), ngram.getCount());
+    }
+
+    @Override
+    public List<NgramDto> getListOfNgrams(NgramsListQueryObject ngramsListQuery) {
+        if (ngramsListQuery == null)
+            return null;
+
+        NgramsListDaoQueryObject ngramsDaoQO = NgramsListQueryObjectToDaoQueryObjectConverter.convert(ngramsListQuery);
+        return NgramsListDaoToDto.convert(ngramsDao.extractListOfNgrams(ngramsDaoQO));
+    }
+
+    @Override
+    public int getAmountOfNgramsInDatabase() {
+        return ngramsDao.extractAmountOfNgrams();
+    }
+}

File database-services-impl/src/main/java/databaseServicesImplementation/NgramsListDaoToDto.java

View file
+package databaseServicesImplementation;
+
+import dao.entities.Ngram;
+import databaseServicesApi.NgramDto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class NgramsListDaoToDto {
+    public static List<NgramDto> convert(List<Ngram> listToConvert) {
+        List<NgramDto> listToReturn = new ArrayList<NgramDto>(listToConvert.size());
+
+        for (Ngram element : listToConvert) {
+            listToReturn.add(new NgramDto(element.getData(), element.getCount()));
+        }
+
+        return listToReturn;
+    }
+}

File database-services-impl/src/main/java/databaseServicesImplementation/NgramsListQueryObjectToDaoQueryObjectConverter.java

View file
+package databaseServicesImplementation;
+
+import dao.daoQueryObjects.NgramsListDaoQueryObject;
+import databaseServicesApi.NgramsListQueryObject;
+
+public class NgramsListQueryObjectToDaoQueryObjectConverter {
+    public static NgramsListDaoQueryObject convert(NgramsListQueryObject ngramsListQuery) {
+        return new NgramsListDaoQueryObject(
+                ngramsListQuery.getAmount(),
+                ngramsListQuery.getOffsetPage(),
+                ngramsListQuery.getOrderByFieldName(),
+                ngramsListQuery.getOrder());
+    }
+}

File database-services-impl/src/main/java/databaseServicesImplementation/WordsJdbcReader.java

View file
+package databaseServicesImplementation;
+
+import dao.NgramsDao;
+import dao.WordsDao;
+import dao.daoQueryObjects.WordsListDaoQueryObject;
+import dao.jdbcDao.JdbcNgramsDao;
+import dao.jdbcDao.JdbcWordsDao;
+import databaseServicesApi.WordForNgramWithCountDto;
+import databaseServicesApi.WordsDatabaseReaderInterface;
+import databaseServicesApi.WordsListQueryObject;
+import jdbcUtilities.JdbcH2DataSource;
+import org.apache.commons.lang3.StringUtils;
+
+import java.sql.Connection;
+import java.util.List;
+
+public class WordsJdbcReader implements WordsDatabaseReaderInterface {
+    private final WordsDao wordsDao;
+    private final NgramsDao ngramsDao;
+
+    public WordsJdbcReader() {
+        Connection connection = JdbcH2DataSource.getDBConnection();
+
+        wordsDao = new JdbcWordsDao(connection);
+        ngramsDao = new JdbcNgramsDao(connection);
+    }
+
+    @Override
+    public List<WordForNgramWithCountDto> getListOfWordsWithCounters(WordsListQueryObject wordsListQuery) {
+        if (wordsListQuery == null)
+            return null;
+
+        int ngramId = ngramsDao.getIdForNgram(wordsListQuery.getNgramData());
+        WordsListDaoQueryObject wrdsDaoQO = WordsListQueryObjectToDaoQueryObjectConverter.convert(ngramId, wordsListQuery);
+        return WordsListDaoToDto.convert(wordsDao.findAndExtractListOfWordsForNgramByPartialWordMatch(wrdsDaoQO));
+    }
+
+    @Override
+    public int getAmountOfWordsWithCountersInDatabase(String ngramData, String partOfWord) {
+        if (StringUtils.isEmpty(ngramData) || StringUtils.isEmpty(partOfWord))
+            return 0;
+
+        int ngramId = ngramsDao.getIdForNgram(ngramData);
+        if (ngramId > 0) {
+            return wordsDao.extractAmountOfWordsForNgramByItsDataPartialMatch(ngramId, partOfWord);
+        }
+        return 0;
+    }
+}

File database-services-impl/src/main/java/databaseServicesImplementation/WordsListDaoToDto.java

View file
+package databaseServicesImplementation;
+
+import dao.entities.WordForNgramWithCount;
+import databaseServicesApi.WordForNgramWithCountDto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class WordsListDaoToDto {
+    public static List<WordForNgramWithCountDto> convert(List<WordForNgramWithCount> listToConvert) {
+        List<WordForNgramWithCountDto> listToReturn = new ArrayList<WordForNgramWithCountDto>(listToConvert.size());
+
+        for (WordForNgramWithCount element : listToConvert) {
+            listToReturn.add(new WordForNgramWithCountDto(element.getWord(), element.getCount()));
+        }
+
+        return listToReturn;
+    }
+}

File database-services-impl/src/main/java/databaseServicesImplementation/WordsListQueryObjectToDaoQueryObjectConverter.java

View file
+package databaseServicesImplementation;
+
+import dao.daoQueryObjects.WordsListDaoQueryObject;
+import databaseServicesApi.WordsListQueryObject;
+
+public class WordsListQueryObjectToDaoQueryObjectConverter {
+    public static WordsListDaoQueryObject convert(int ngramId, WordsListQueryObject wordsListQuery) {
+        return new WordsListDaoQueryObject(ngramId,
+                wordsListQuery.getOffsetPage(),
+                wordsListQuery.getAmountOfElements(),
+                wordsListQuery.getWordToSearchPattern(),
+                wordsListQuery.getOrderByFieldName(),
+                wordsListQuery.getOrder());
+    }
+}

File database-services-impl/src/main/java/services/DatabaseAdder.java

-package services;
-
-import dao.*;
-import dao.entities.dbTables.Ngram;
-import dao.entities.dbTables.NgramToWord;
-import dao.entities.dbTables.WordToPhrase;
-import dao.exceptions.IllegalInputSizeException;
-import dao.jdbcDao.*;
-import dataStructures.PhraseDataHolder;
-import dataStructures.WordWithNgrams;
-import jdbcUtilities.JdbcH2DataSource;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-public class DatabaseAdder implements DatabaseAdderInterface {
-    private Connection connection;
-
-    private PhrasesDao phrasesDao;
-    private WordsDao wordsDao;
-    private NgramsDao ngramsDao;
-    private WordsToPhrasesDao wordsToPhrasesDao;
-    private NgramsToWordsDao ngramsToWordsDao;
-
-    public DatabaseAdder() throws SQLException {
-        connection = JdbcH2DataSource.getDBConnection();
-
-        connection.setAutoCommit(false);
-        connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-
-        phrasesDao = new JdbcPhrasesDao(connection);
-        wordsDao = new JdbcWordsDao(connection);
-        ngramsDao = new JdbcNgramsDao(connection);
-
-        wordsToPhrasesDao = new JdbcWordsToPhrasesDao(connection);
-        ngramsToWordsDao = new JdbcNgramsToWordsDao(connection);
-    }
-
-    public void clearDatabase() throws SQLException {
-        // Clear data in tables phase
-        ngramsToWordsDao.removeAllEntetiesFromTable();
-        wordsToPhrasesDao.removeAllEntetiesFromTable();
-        ngramsDao.removeAllEntetiesFromTable();
-        wordsDao.removeAllEntetiesFromTable();
-        phrasesDao.removeAllEntetiesFromTable();
-
-        connection.commit();
-    }
-
-    @Override
-    public void addToDatabase(PhraseDataHolder data) throws Exception {
-        try {
-            // Insert phrase into table
-            int phraseDbId = phrasesDao.insertNewPhrase(data.getPhrase());
-
-            // Insert Elements into table
-            for (WordWithNgrams wordWithNgrams : data.getWordsWithNgramsList()) {
-                String currentWordData = wordWithNgrams.getWord();
-
-                boolean isWordNew = false;
-
-                int wordDbId = wordsDao.findWord(currentWordData);
-                if (wordDbId == 0) {
-                    wordDbId = wordsDao.insertNewWord(currentWordData, phraseDbId);
-                    isWordNew = true;
-                }
-
-                WordToPhrase wordToPhrase = wordsToPhrasesDao.findWordToPhrase(wordDbId, phraseDbId);
-                if (wordToPhrase == null) {
-                    wordsToPhrasesDao.insertNewWordToPhrase(wordDbId, phraseDbId);
-                } else {
-                    wordToPhrase.incrementCounter();
-                    wordsToPhrasesDao.updateWordToPhraseCounter(wordToPhrase);
-                }
-
-                if (wordWithNgrams.getNgramsList() != null) {
-                    for (String currentNgramData : wordWithNgrams.getNgramsList()) {
-                        // Find and insert ngram into dbTables or increment ngram counter
-                        Ngram ngram = ngramsDao.findByDataString(currentNgramData);
-                        if (ngram == null) {
-                            int newNgramDbIndex = ngramsDao.insertNewNgram(currentNgramData);
-                            ngram = new Ngram(newNgramDbIndex, currentNgramData, 1);
-                        } else {
-                            ngram.incrementCounter();
-                            ngramsDao.updateNgramCounter(ngram);
-                        }
-
-                        // Find and insert ngram_to_word relation of increment ngram in word counter
-                        NgramToWord ngramToWord = ngramsToWordsDao.findNgramToWord(ngram.getId(), wordDbId);
-                        if (ngramToWord == null) {
-                            ngramsToWordsDao.insertNewNgramsToWords(ngram.getId(), wordDbId);
-                        } else {
-                            if (isWordNew) {
-                                ngramToWord.incrementCounter();
-                                ngramsToWordsDao.updateNgramToWordCounter(ngramToWord);
-                            }
-                        }
-                    }
-                    connection.commit();
-                }
-            }
-            connection.commit();
-        } catch (SQLException e) {
-            connection.rollback();
-            System.out.println(e.getMessage());
-        } catch (IllegalInputSizeException e) {
-            connection.rollback();
-            throw new RuntimeException(e);
-        }
-    }
-
-    @Override
-    public void closeDatabaseConnection() throws SQLException {
-        connection.close();
-    }
-
-    protected void finalize() throws Throwable {
-        try {
-            closeDatabaseConnection();
-        } finally {
-            super.finalize();
-        }
-    }
-}

File database-services-impl/src/main/java/services/NgramsJdbcReader.java

-package services;
-
-import dao.NgramsDao;
-import dao.daoQueryObjects.NgramsListDaoQueryObject;
-import dao.jdbcDao.JdbcNgramsDao;
-import dtConverters.NgramsListDaoToDto;
-import dtObjects.Ngram;
-import jdbcUtilities.JdbcH2DataSource;
-import queryConverters.NgramsListQueryObjectToDaoQueryObjectConverter;
-import queryObjects.NgramsListQueryObject;
-
-import java.util.List;
-
-public class NgramsJdbcReader implements NgramsDatabaseReaderInterface {
-    private final NgramsDao ngramsDao;
-
-    public NgramsJdbcReader() {
-        ngramsDao = new JdbcNgramsDao(JdbcH2DataSource.getDBConnection());
-    }
-
-    @Override
-    public Ngram searchNgramByDataFullMatch(String ngramData) {
-        dao.entities.dbTables.Ngram ngram = ngramsDao.findByDataString(ngramData);
-        return new Ngram(ngram.getData(), ngram.getCount());
-    }
-
-    @Override
-    public List<Ngram> getListOfNgrams(NgramsListQueryObject ngramsListQuery) {
-        if (ngramsListQuery == null)
-            return null;
-
-        NgramsListDaoQueryObject ngramsDaoQO = NgramsListQueryObjectToDaoQueryObjectConverter.convert(ngramsListQuery);
-        return NgramsListDaoToDto.convert(ngramsDao.extractListOfNgrams(ngramsDaoQO));
-    }
-
-    @Override
-    public int getAmountOfNgramsInDatabase() {
-        return ngramsDao.extractAmountOfNgrams();
-    }
-}

File database-services-impl/src/main/java/services/WordsJdbcReader.java

-package services;
-
-import dao.NgramsDao;
-import dao.WordsDao;
-import dao.daoQueryObjects.WordsListDaoQueryObject;
-import dao.jdbcDao.JdbcNgramsDao;
-import dao.jdbcDao.JdbcWordsDao;
-import dtConverters.WordsListDaoToDto;
-import dtObjects.WordForNgramWithCount;
-import jdbcUtilities.JdbcH2DataSource;
-import org.apache.commons.lang3.StringUtils;
-import queryConverters.WordsListQueryObjectToDaoQueryObjectConverter;
-import queryObjects.WordsListQueryObject;
-
-import java.sql.Connection;
-import java.util.List;
-
-public class WordsJdbcReader implements WordsDatabaseReaderInterface {
-    private final WordsDao wordsDao;
-    private final NgramsDao ngramsDao;
-
-    public WordsJdbcReader() {
-        Connection connection = JdbcH2DataSource.getDBConnection();
-
-        wordsDao = new JdbcWordsDao(connection);
-        ngramsDao = new JdbcNgramsDao(connection);
-    }
-
-    @Override
-    public List<WordForNgramWithCount> getListOfWordsWithCounters(WordsListQueryObject wordsListQuery) {
-        if (wordsListQuery == null)
-            return null;
-
-        int ngramId = ngramsDao.getIdForNgram(wordsListQuery.getNgramData());
-        WordsListDaoQueryObject wrdsDaoQO = WordsListQueryObjectToDaoQueryObjectConverter.convert(ngramId, wordsListQuery);
-        return WordsListDaoToDto.convert(wordsDao.findAndExtractListOfWordsForNgramByPartialWordMatch(wrdsDaoQO));
-    }
-
-    @Override
-    public int getAmountOfWordsWithCountersInDatabase(String ngramData, String partOfWord) {
-        if (StringUtils.isEmpty(ngramData) || StringUtils.isEmpty(partOfWord))
-            return 0;
-
-        int ngramId = ngramsDao.getIdForNgram(ngramData);
-        if (ngramId > 0) {
-            return wordsDao.extractAmountOfWordsForNgramByItsDataPartialMatch(ngramId, partOfWord);
-        }
-        return 0;
-    }
-}

File libngram-database/src/main/java/dao/AbstractDao.java

View file
 package dao;
 
-import dao.exceptions.IllegalInputSizeException;
+import dao.jdbcDao.IllegalInputSizeException;
 
 import java.sql.*;
 

File libngram-database/src/main/java/dao/NgramsDao.java

View file
 package dao;
 
 import dao.daoQueryObjects.NgramsListDaoQueryObject;
-import dao.entities.dbTables.Ngram;
+import dao.entities.Ngram;
 
 import java.util.List;
 

File libngram-database/src/main/java/dao/NgramsToWordsDao.java

View file
 package dao;
 
-import dao.entities.dbTables.NgramToWord;
+import dao.entities.NgramToWord;
 
 public interface NgramsToWordsDao {
 

File libngram-database/src/main/java/dao/WordsDao.java

View file
 package dao;
 
 import dao.daoQueryObjects.WordsListDaoQueryObject;
-import dao.entities.logical.WordForNgramWithCount;
+import dao.entities.WordForNgramWithCount;
 
 import java.util.List;
 

File libngram-database/src/main/java/dao/WordsToPhrasesDao.java

View file
 package dao;
 
-import dao.entities.dbTables.WordToPhrase;
+import dao.entities.WordToPhrase;
 
 public interface WordsToPhrasesDao {
 

File libngram-database/src/main/java/dao/daoQueryObjects/NgramsListDaoQueryObject.java

View file
 package dao.daoQueryObjects;
 
-import dao.queryOptions.NgramsSortFieldName;
-import dao.queryOptions.Order;
-
 public class NgramsListDaoQueryObject {
     //required
     private int amount;

File libngram-database/src/main/java/dao/daoQueryObjects/NgramsSortFieldName.java

View file
+package dao.daoQueryObjects;
+
+public enum NgramsSortFieldName {
+    name, count
+}

File libngram-database/src/main/java/dao/daoQueryObjects/Order.java

View file
+package dao.daoQueryObjects;
+
+public enum Order {
+    asc, desc
+}

File libngram-database/src/main/java/dao/daoQueryObjects/WordsListDaoQueryObject.java

View file
 package dao.daoQueryObjects;
 
-import dao.queryOptions.Order;
-import dao.queryOptions.WordsSortFieldName;
-
 public class WordsListDaoQueryObject {
     // required
     private final int ngramId;

File libngram-database/src/main/java/dao/daoQueryObjects/WordsSortFieldName.java

View file
+package dao.daoQueryObjects;
+
+public enum WordsSortFieldName {
+    word, count
+}

File libngram-database/src/main/java/dao/entities/Ngram.java

View file
+package dao.entities;
+
+import dao.jdbcDao.IllegalInputSizeException;
+
+public class Ngram {
+    private static final int MAXIMUM_NGRAM_STRING_LENGTH = 20;
+
+    public static final String NGRAM_ID_COLUMN_NAME = "id";
+    public static final String NGRAM_DATA_COLUMN_NAME = "n_gram_data";
+    public static final String NGRAM_COUNT_COLUMN_NAME = "n_gram_count";
+
+    private int id;
+    private final String data;
+    private int count = 0;
+
+    public Ngram(String ngramData) throws IllegalInputSizeException {
+        validateData(ngramData);
+
+        this.data = ngramData;
+    }
+
+    public Ngram(int ngramId, String ngramData, int ngramCount) throws IllegalInputSizeException {
+        this(ngramData);
+
+        validateCount(ngramCount);
+        this.id = ngramId;
+        this.count = ngramCount;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public int getCount() {
+        return count;
+    }
+
+    public void incrementCounter() {
+        count++;
+    }
+
+    private void validateData(String ngramData) throws IllegalInputSizeException {
+        if (ngramData == null || ngramData.isEmpty()) {
+            throw new IllegalArgumentException("Ngram data cannot be null or empty.");
+        }
+
+        if (ngramData.length() < 0 && ngramData.length() > MAXIMUM_NGRAM_STRING_LENGTH) {
+            throw new IllegalInputSizeException("Ngram string length exceeded allowed " + MAXIMUM_NGRAM_STRING_LENGTH + " symbols limit.");
+        }
+    }
+
+    private void validateCount(int ngramCount) {
+        if (ngramCount <= 0) {
+            throw new IllegalArgumentException("Ngram counter can't have negative value.");
+        }
+    }
+}

File libngram-database/src/main/java/dao/entities/NgramToWord.java

View file
+package dao.entities;
+
+public class NgramToWord {
+    public static final String NGRAM_TO_WORD_NGRAM_ID_COLUMN_NAME = "ngram_id";
+    public static final String NGRAM_TO_WORD_WORD_ID_COLUMN_NAME = "word_id";
+    public static final String NGRAM_TO_WORD_NGRAM_IN_WORD_COUNT_COLUMN_NAME = "ngram_in_word_count";
+
+    private int ngramId;
+    private int wordId;
+    private int ngramInWordCount;
+
+    public NgramToWord(int ngramId, int wordId, int ngramInWordCount) {
+        this.ngramId = ngramId;
+        this.wordId = wordId;
+        this.ngramInWordCount = ngramInWordCount;
+    }
+
+    public int getNgramId() {
+        return ngramId;
+    }
+
+    public int getWordId() {
+        return wordId;
+    }
+
+    public int getNgramInWordCount() {
+        return ngramInWordCount;
+    }
+
+    public void incrementCounter() {
+        ngramInWordCount++;
+    }
+}

File libngram-database/src/main/java/dao/entities/WordForNgramWithCount.java

View file
+package dao.entities;
+
+public class WordForNgramWithCount {
+    private String word;
+    private int count;
+
+    public WordForNgramWithCount(String word, int count) {
+        this.word = word;
+        this.count = count;
+    }
+
+    public String getWord() {
+        return word;
+    }
+
+    public int getCount() {
+        return count;
+    }
+}

File libngram-database/src/main/java/dao/entities/WordToPhrase.java

View file
+package dao.entities;
+
+public class WordToPhrase {
+    public static final String WORD_TO_PHRASE_WORD_ID_COLUMN_NAME = "word_id";
+    public static final String WORD_TO_PHRASE_PHRASE_ID_COLUMN_NAME = "phrase_id";
+    public static final String WORD_TO_PHRASE_WORDS_IN_PHRASE_COUNT_COLUMN_NAME = "words_in_phrase_count";
+
+    private int wordId;
+    private int phraseId;
+    private int wordToPhraseCount;
+
+    public WordToPhrase(int wordId, int phraseId, int wordToPhraseCount) {
+        this.wordId = wordId;
+        this.phraseId = phraseId;
+        this.wordToPhraseCount = wordToPhraseCount;
+    }
+
+    public int getWordId() {
+        return wordId;
+    }
+
+    public int getPhraseId() {
+        return phraseId;
+    }
+
+    public int getWordToPhraseCount() {
+        return wordToPhraseCount;
+    }
+
+    public void incrementCounter() {
+        wordToPhraseCount++;
+    }
+}

File libngram-database/src/main/java/dao/entities/dbTables/Ngram.java

-package dao.entities.dbTables;
-
-import dao.exceptions.IllegalInputSizeException;
-
-public class Ngram {
-    private static final int MAXIMUM_NGRAM_STRING_LENGTH = 20;
-
-    public static final String NGRAM_ID_COLUMN_NAME = "id";
-    public static final String NGRAM_DATA_COLUMN_NAME = "n_gram_data";
-    public static final String NGRAM_COUNT_COLUMN_NAME = "n_gram_count";
-
-    private int id;
-    private final String data;
-    private int count = 0;
-
-    public Ngram(String ngramData) throws IllegalInputSizeException {
-        validateData(ngramData);
-
-        this.data = ngramData;
-    }
-
-    public Ngram(int ngramId, String ngramData, int ngramCount) throws IllegalInputSizeException {