Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

02 01 amit #83

Merged
merged 2 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/main/java/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1522,12 +1522,14 @@ public void run(){
//update dictionary
dictionaryMutex.lock();
Vector<Integer> details = dictionary.get(term);
if(details.size()==3)
details.remove(2);//the ptr
details.add(lineNum);
dictionary.remove(term);
dictionary.put(term, details);
dictionaryMutex.unlock();
if(details.get(2)==-1) {
if (details.size() == 3)
details.remove(2);//the ptr
details.add(lineNum);
dictionary.remove(term);
dictionary.put(term, details);
dictionaryMutex.unlock();
}

}
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/Model_2.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ public class Model_2 {
private int numOfIndexedDocs;


/**
*
* @param path of posting files
* @param cities to choose
* @param queriesPath the path of query file
* @param toStem
* @param toTreatSemantic
* @param savePath- path to save the results file.
* @return answers for query
* @throws IOException
*/
public Vector<Pair<String,Collection<Document>>> Start(String path, Vector<String> cities, Path queriesPath, boolean toStem, boolean toTreatSemantic, String savePath) throws IOException {
Vector<Pair<String,Collection<Document>>> id_docsCollection= new Vector<>();
HashSet<String> citieshash = new HashSet<>(cities);
Expand All @@ -33,6 +44,16 @@ public Vector<Pair<String,Collection<Document>>> Start(String path, Vector<Strin
/**
* This function is the main function of the program.
*/
/**
*
* @param path of posting files
* @param cities to choose
* @param query
* @param toStem
* @param toTreatSemantic
* @param savePath - path to save the results file.
* @return answers for query
*/
public Collection<Document> Start(String path, Vector<String> cities, String query, boolean toStem, boolean toTreatSemantic, String savePath){
HashSet<String> citieshash = new HashSet<>(cities);
readIndexerInfo(path,toStem);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ReadFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Vector<Pair<String,String>> readQueriesFile(Path filePath) throws
String title = query.getElementsByTag("title").get(0).text();
String desc = query.getElementsByTag("desc").get(0).childNode(0).toString().trim().split(":")[1];
String narr = query.getElementsByTag("narr").get(0).text();
queriesTitels.add(new Pair<String,String>(id,title));
queriesTitels.add(new Pair<String,String>(id,title+" "+desc));
}
return queriesTitels;
}
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/Searcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ else if (Character.isDigit(letter) || letter == '-')
return doc_tf;
}
try {
RandomAccessFile raf = new RandomAccessFile(new File(fullPath), "r");
//RandomAccessFile raf = new RandomAccessFile(new File(fullPath), "r");
BufferedReader reader=new BufferedReader(new FileReader(new File(fullPath)));
int lineNum;
int numOfDocs;
if(dictionary.containsKey(term)) {
Expand All @@ -202,6 +203,7 @@ else if (Character.isDigit(letter) || letter == '-')
//-1 cause we checked
}
_term_docsCounter.put(term,numOfDocs);
/**
for (int i = 0; i <= numOfDocs; i++) {//TODO
raf.seek((lineNum + i) * 8);//TODO
byte[] docLine_bytes = new byte[4];
Expand All @@ -216,6 +218,23 @@ else if (Character.isDigit(letter) || letter == '-')

}
raf.close();
**/
for(int i=0;i<lineNum-13;i++){
String justLine=reader.readLine();
}
for(int i=0;i<numOfDocs-1;i++){
String termLine=reader.readLine();
String[] details=termLine.split("~");
if(!details[0].equalsIgnoreCase(term)){
System.out.println("somethings is wrong: "+term);
}
else {
int docLine = (Integer.parseInt(details[1]));
int tf = (Integer.parseInt(details[2]));
if (!doc_tf.keySet().contains(docLine))
doc_tf.put(docLine, tf);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
Expand Down