Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

Phase02 clean code corrected #4

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

MohammadHDehghani
Copy link
Collaborator

اصول SOLID و clean code روی فاز قبلی پروژه اعمال شدند.

Comment on lines 13 to 18
for (String word : words) {
Set<String> searchResult = WordFileNameFinder.searchWord(word, invertedIndex);
if(finalResult.isEmpty()){
finalResult.addAll(searchResult);
}
else{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method extracted

e.printStackTrace();
}
} else {
System.out.println("Specified path is not a directory.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception is used.

Comment on lines 31 to 59
Map<String, Set<String>> invertedIndex = new HashMap<>();

for (String fileName : fileNamesInFolder) {
try {
File file = new File(directoryPath + "/" + fileName);
Scanner myReader = new Scanner(file);

while (myReader.hasNextLine()) {
Set<String> documentIds = new HashSet<String>();
documentIds.add(fileName);

String data = myReader.nextLine();
String[] splittedData = data.split(" ");

for (String word : splittedData) {
// Ignoring empty words
if (word == "") {
continue;
}
// Inserting new entry to inverted index table
invertedIndex.computeIfAbsent(word, k -> new HashSet<>()).addAll(documentIds);
}
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class extracted.

Comment on lines 16 to 28
// Getting directory path and user input
Scanner myScanner = new Scanner(System.in);

System.out.print("Enter Data Folder Path: ");
final String directoryPath = myScanner.nextLine();

System.out.print("Enter Search Query: ");
final String userInput = myScanner.nextLine();

myScanner.close();

// Finding name of all files that are in EnglishData directory
ArrayList<String> fileNamesInFolder = FileReader.getFileNames(directoryPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method extracted.

Comment on lines 60 to 65

// Categorizing command words into or_words, necessary and forbidden groups
ArrayList<String> necessaryWords = WordCategorizer.categorizer(userInput, "");
ArrayList<String> orWords = WordCategorizer.categorizer(userInput, "+");
ArrayList<String> notWords = WordCategorizer.categorizer(userInput, "-");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method extracted.

ArrayList<String> orWords = WordCategorizer.categorizer(userInput, "+");
ArrayList<String> notWords = WordCategorizer.categorizer(userInput, "-");

// Initializing some sets for forming final answer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class extracted.


public class WordFileNameFinder {
// Searchs a word in inverted index then returns name of files that are containing that word
public static Set<String> searchWord(String word, Map<String, Set<String>> invertedIndex) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invertedIndex should be a class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now we have another class called InvertedIndexWordSearch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants