StringBuffer text = new StringBuffer();
for (Sentence sentence : sentences) {
text.append(sentence.getText());
}
article.setText(text.toString());
SimpleDAO simpleDAO = DAOFactory.getDao();
article.setId(simpleDAO.addObjects(article));
Map<String, SubjectsEntity> subjectsEntityMap = new HashMap<String, SubjectsEntity>();
Map<String, Double> subjectsMap = calculateSubjectFrequency();
for (String word : subjectsMap.keySet()) {
SubjectsEntity subjectsEntity = new SubjectsEntity();
subjectsEntity.setFreq(subjectsMap.get(word).floatValue());
subjectsEntity.setWord(word);
subjectsEntity.setArticle(article);
subjectsEntityMap.put(word, subjectsEntity);
subjectsEntity.setId(simpleDAO.addObjects(subjectsEntity));
}
article.setSubjects(new ArrayList<SubjectsEntity>(subjectsEntityMap.values()));
List<TripletEntity> tripletEntities = new ArrayList<TripletEntity>();
for (Triplet triplet : tree.keySet()) {
TripletEntity tripletEntity = createEntityFromTriplet(triplet, subjectsEntityMap);
tripletEntities.add(tripletEntity);
tripletEntities.addAll(treeToList(tripletEntity, tree.get(triplet), subjectsEntityMap));
}
for (TripletEntity tripletEntity : tripletEntities) {
tripletEntity.setId(simpleDAO.addObjects(tripletEntity));
}
article.setTriplets(tripletEntities);
simpleDAO.updateObject(article);
}