Last active
April 23, 2017 10:20
-
-
Save waldemarGr/3663b48756eb73d47220293f2685003e to your computer and use it in GitHub Desktop.
jop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package memo.model; | |
import javafx.collections.transformation.SortedList; | |
import javax.persistence.*; | |
import java.util.List; | |
/** | |
* Created by wg on 2017-02-07. | |
*/ | |
@Entity | |
public class Book { | |
@Id | |
@GeneratedValue | |
private Long id; | |
private memo.model.Category Category; | |
private String title; | |
private String FullText; | |
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) | |
@JoinColumn | |
private List<WordsInBook> wordsInBooks; | |
public Book() { | |
} | |
public Book(memo.model.Category category, String title) { | |
Category = category; | |
this.title = title; | |
} | |
public Long getId() { | |
return id; | |
} | |
public Book setId(Long id) { | |
this.id = id; | |
return this; | |
} | |
public memo.model.Category getCategory() { | |
return Category; | |
} | |
public Book setCategory(memo.model.Category category) { | |
Category = category; | |
return this; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public Book setTitle(String title) { | |
this.title = title; | |
return this; | |
} | |
public String getFullText() { | |
return FullText; | |
} | |
public Book setFullText(String fullText) { | |
FullText = fullText; | |
return this; | |
} | |
public List<WordsInBook> getWordsInBooks() { | |
return wordsInBooks; | |
} | |
public Book setWordsInBooks(List<WordsInBook> wordsInBooks) { | |
this.wordsInBooks = wordsInBooks; | |
return this; | |
} | |
@Override | |
public String toString() { | |
return "Book{" + | |
"id=" + id + | |
", Category=" + Category + | |
", title='" + title + '\'' + | |
// ",\n FullText='" + FullText.substring(0,Math.min(FullText.length(), 100)) + '\'' + | |
",\n wordsInBooks=" + wordsInBooks + | |
'}'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package memo.model.repository; | |
import memo.model.Book; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.repository.CrudRepository; | |
import java.util.List; | |
/** | |
* Created by wg on 2017-02-08. | |
*/ | |
public interface BookRepository extends JpaRepository<Book,Long>{ | |
// List<Book> findBy(String name); | |
void setOrUpdate(Book book); | |
} | |
English |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package memo.model; | |
import memo.NLP.stanford.PartOfSpeach; | |
import javax.persistence.*; | |
/** | |
* Created by wg on 2017-02-06. | |
*/ | |
@Entity | |
@Table(indexes = { @Index(name = "IDX_MYIDX1", columnList = "word,partOfSpeach" ) }) | |
public class English implements Word { | |
@Id | |
@GeneratedValue | |
private Long id; | |
private String word; | |
private PartOfSpeach partOfSpeach; | |
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) | |
@JoinColumn(name = "id_polish_word") | |
private Polish polishWord; | |
public English() { | |
} | |
public English(String word) { | |
this.word = word; | |
} | |
@Override | |
public Long getId() { | |
return id; | |
} | |
@Override | |
public void setId(Long id) { | |
this.id = id; | |
} | |
@Override | |
public String getWord() { | |
return word; | |
} | |
@Override | |
public void setWord(String word) { | |
this.word = word; | |
} | |
// public Polish getPolishWors(){ | |
// return polishWord; | |
// } | |
public void setPolishWord(Polish polishWord){ | |
this.polishWord=polishWord; | |
} | |
public English setPolishWordO(Polish polishWord){ | |
this.polishWord=polishWord; | |
return this; | |
} | |
public PartOfSpeach getPartOfSpeach() { | |
return partOfSpeach; | |
} | |
public void setPartOfSpeach(PartOfSpeach partOfSpeach) { | |
this.partOfSpeach = partOfSpeach; | |
} | |
public English setPartOfSpeachR(PartOfSpeach partOfSpeach) { | |
this.partOfSpeach = partOfSpeach; | |
return this; | |
} | |
public Polish getPolishWord() { | |
return polishWord; | |
} | |
@Override | |
public String toString() { | |
return "English{" + | |
"id=" + id + | |
", word='" + word + '\'' + | |
", partOfSpeach=" + partOfSpeach + | |
", polishWord=" + polishWord + | |
'}'; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
English english = (English) o; | |
if (word != null ? !word.equals(english.word) : english.word != null) return false; | |
if (partOfSpeach != english.partOfSpeach) return false; | |
return true; | |
} | |
@Override | |
public int hashCode() { | |
int result = 0; | |
result = 31 * result + (word != null ? word.hashCode() : 0); | |
result = 31 * result + (partOfSpeach != null ? partOfSpeach.hashCode() : 0); | |
return result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package memo.model.repository; | |
import memo.model.English; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
/** | |
* Created by wg on 2017-02-06. | |
*/ | |
public interface EnglishRepository extends JpaRepository<English, Long> { | |
List<English> findByWord(String word); | |
// List<English> saveIfNotExist(List<English> list); | |
// English saveIfNotExist(English e); | |
// Word findWord(String word); | |
//@Override | |
// default List<English> save(List<English> newestEnglishList) { | |
// List<English> newList = new ArrayList<>(); | |
// for (English e : newestEnglishList) { | |
// List<English> byWord = findByWord(e.getWord()); | |
// if (byWord.size() < 0) { | |
// newList.add(e); | |
// } else { | |
// English newEnglish = save(e); | |
// newList.add(newEnglish); | |
// } | |
// } | |
// return newList; | |
// } | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package memo; | |
import org.apache.log4j.Level; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Component; | |
import javax.annotation.PostConstruct; | |
import java.util.List; | |
/** | |
*/ | |
@Component | |
public class RunAtStart { | |
private final EnglishRepository englishRepository; | |
private final PolishRepository polishRepository; | |
private final BookRepository bookRepository; | |
private final WordsInBookRepository wordsInBookRepository; | |
private final SaveToDb saveToDb; | |
private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(RunAtStart.class); | |
private final Translate translate; | |
@Autowired | |
public RunAtStart(EnglishRepository englishRepository, PolishRepository polishRepository, BookRepository bookRepository, WordsInBookRepository wordsInBookRepository, SaveToDb saveToDb, Translate translate) { | |
this.englishRepository = englishRepository; | |
this.polishRepository = polishRepository; | |
this.bookRepository = bookRepository; | |
this.wordsInBookRepository = wordsInBookRepository; | |
this.saveToDb = saveToDb; | |
this.translate = translate; | |
} | |
public void testDuplicatWords() {//test2 | |
Book book = new Book(); | |
TagerPartOfSpeach tagerPartOfSpeach = new TagerPartOfSpeach(); | |
String path = "src\\main\\resources\\textRestApiWikipediaOneLongLine.txt"; | |
ReadFile readFile = new ReadFile(path); | |
String textFromBook = readFile.getText(); | |
List<WordsInBook> wordsInBookFromText = tagerPartOfSpeach.getWordsInBookFromText(textFromBook); | |
book.setCategory(Category.book) | |
.setTitle("tileBook") | |
// .setFullText(textFromBook) | |
.setWordsInBooks(wordsInBookFromText); | |
try { | |
bookRepository.save(book); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
bookRepository.findAll().forEach(System.out::println); | |
//Add duplicate | |
Book book2 = new Book(); | |
List<WordsInBook> wordsInBookFromText2 = tagerPartOfSpeach.getWordsInBookFromText(textFromBook); | |
book2.setCategory(Category.youTubbe) | |
.setTitle("tileBook2") | |
// .setFullText(textFromBook) | |
.setWordsInBooks(wordsInBookFromText2); | |
try { | |
bookRepository.save(book2); | |
// saveToDb.saveOrUpdate(book2); | |
} catch (Exception e) { | |
// log.log(Level.INFO, e); | |
e.printStackTrace(); | |
} | |
bookRepository.findAll().forEach(System.out::println); | |
} | |
} | |
@PostConstruct | |
public void runAtStart() { | |
testDuplicatWords(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package memo.model; | |
import org.hibernate.annotations.Proxy; | |
import javax.persistence.*; | |
/** | |
* Created by wg on 2017-02-10. | |
*/ | |
@Proxy(lazy=false) | |
@Entity | |
public class WordsInBook { | |
@Id | |
@GeneratedValue | |
private Long id; | |
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) | |
@JoinColumn(name = "id_english_word") | |
private English english; | |
private Long count; | |
public WordsInBook() { | |
} | |
public WordsInBook( English english, Long count) { | |
this.english = english; | |
this.count = count; | |
} | |
public Long getId() { | |
return id; | |
} | |
public void setId(Long id) { | |
this.id = id; | |
} | |
public English getEnglish() { | |
return english; | |
} | |
public void setEnglish(English english) { | |
this.english = english; | |
} | |
public Long getCount() { | |
return count; | |
} | |
public void setCount(Long count) { | |
this.count = count; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
WordsInBook that = (WordsInBook) o; | |
if (id != null ? !id.equals(that.id) : that.id != null) return false; | |
if (english != null ? !english.equals(that.english) : that.english != null) return false; | |
return count != null ? count.equals(that.count) : that.count == null; | |
} | |
@Override | |
public int hashCode() { | |
int result = id != null ? id.hashCode() : 0; | |
result = 31 * result + (english != null ? english.hashCode() : 0); | |
result = 31 * result + (count != null ? count.hashCode() : 0); | |
return result; | |
} | |
@Override | |
public String toString() { | |
return "\nWordsInBook{" + | |
"id=" + id + | |
", english=" + english + | |
", count=" + count + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment