Skip to content

Commit

Permalink
added methods to clean
Browse files Browse the repository at this point in the history
  • Loading branch information
parsasharify committed Jul 25, 2021
1 parent bd7cc9a commit 789ad36
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
6 changes: 2 additions & 4 deletions src/main/java/InvertedIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public void indexFile(File file) throws IOException {
public Set<String> search(ArrayList<String> wordsToFind) {
Set<String> answer = new HashSet<>();
for (String words : wordsToFind) {

String word = words.toLowerCase();
for (String key : indexedWords.keySet()) {
Matcher matcher = Pattern.compile(word).matcher(key);
Expand Down Expand Up @@ -113,10 +112,9 @@ public Set<String> findCommonWords(ArrayList<Set<String>> wordsToFindCommon) {
private static class Tuple {
private final int fileNumber;

public Tuple(int fileno) {
this.fileNumber = fileno;
public Tuple(int fileNumber) {
this.fileNumber = fileNumber;
}

}
}

5 changes: 3 additions & 2 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

public class Main {
public static void main(String[] args) {
preprocesses();
}

public static void preprocesses() {
File directoryPath = new File("C:\\Users\\ASUS\\IdeaProjects\\codestar\\src\\main\\resources\\EnglishData");
File[] filesList = directoryPath.listFiles();


try {
InvertedIndex idx = new InvertedIndex();
assert filesList != null;
Expand Down
44 changes: 29 additions & 15 deletions src/main/java/TakeInput.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main.java;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TakeInput {

public TakeInput(InvertedIndex idx) {
System.out.println("1");
getOrder(idx);
}

Expand All @@ -15,26 +15,40 @@ public void getOrder(InvertedIndex idx) {
while (true) {
String input = scanner.nextLine();
String[] inputSplited = input.split("(\\s+)");
if (input.equals("--back"))
break;
ArrayList<String> plusStrings = new ArrayList<>();
ArrayList<String> minusStrings = new ArrayList<>();
ArrayList<String> normalStrings = new ArrayList<>();
for (String string : inputSplited) addItemToOneOfThreeArrayLists(string, plusStrings, minusStrings, normalStrings);
Set<String> answer = idx.search(plusStrings);
Set<String> toDelete = idx.search(minusStrings);
ArrayList<Set<String>> commons = new ArrayList<>();
for (String normalString : normalStrings) {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(normalString);
commons.add(idx.search(arrayList));
}
answer = idx.findCommonFiles(answer, commons);
System.out.println(answer);
answer = idx.deleteGivenFiles(answer, toDelete);
for (String s : answer) System.out.println(s);
for (String string : inputSplited)
addItemToOneOfThreeArrayLists(string, plusStrings, minusStrings, normalStrings);
showResult(processes(idx, plusStrings, minusStrings, normalStrings));
}
}

private void showResult(Set<String> answer) {
for (String s : answer) System.out.println(s);

}

private Set<String> processes(InvertedIndex idx, ArrayList<String> plusStrings,
ArrayList<String> minusStrings, ArrayList<String> normalStrings) {
Set<String> answer = idx.search(plusStrings);
Set<String> toDelete = idx.search(minusStrings);
ArrayList<Set<String>> commons = new ArrayList<>();
for (String normalString : normalStrings) {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(normalString);
commons.add(idx.search(arrayList));
}
answer = idx.findCommonFiles(answer, commons);
System.out.println(answer);
answer = idx.deleteGivenFiles(answer, toDelete);
return answer;
}

private void addItemToOneOfThreeArrayLists(String string, ArrayList<String> plusStrings, ArrayList<String> minusStrings, ArrayList<String> normalStrings) {
private void addItemToOneOfThreeArrayLists(String string, ArrayList<String> plusStrings,
ArrayList<String> minusStrings, ArrayList<String> normalStrings) {
Pattern pattern = Pattern.compile("^\\+(.+)$");
Matcher matcher = pattern.matcher(string);
Pattern pattern1 = Pattern.compile("^-(.+)$");
Expand Down

0 comments on commit 789ad36

Please sign in to comment.