-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4348b85
commit 4330e70
Showing
4 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="var" path="ECLIPSE_HOME"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>brmson-cmu</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2014 Carnegie Mellon University | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package edu.cmu.lti.oaqa.util; | ||
|
||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
import java.util.Hashtable; | ||
import java.util.List; | ||
|
||
import edu.cmu.lti.oaqa.util.WebSearchCache; | ||
|
||
public class BingSearcher { | ||
private String mCacheId = "Bing"; | ||
private WebSearchCache mRetrievalCache = null; | ||
private Hashtable<String, ArrayList<SearchResult>> mCacheStorage = null;; | ||
private int mResNum = 100; | ||
private String mAccountKey; | ||
|
||
|
||
/** | ||
* | ||
* Initialize a Bing retrieval class. | ||
* | ||
* @param accountKey A Bing API key for the Web search, | ||
* can be retrieved at https://datamarket.azure.com/dataset/bing/searchweb. | ||
* @param cachePath A path to the file, where we cache retrieved results. | ||
* @param resNum A maximum number of results to return. | ||
* | ||
*/ | ||
BingSearcher(String accountKey, | ||
String cachePath, | ||
int resNum) { | ||
mAccountKey = accountKey; | ||
mResNum = resNum; | ||
mRetrievalCache = new WebSearchCache(cachePath); | ||
mCacheStorage = mRetrievalCache.loadCache(mCacheId); | ||
if (mCacheStorage == null) | ||
mCacheStorage = new Hashtable<String, ArrayList<SearchResult>>(); | ||
|
||
} | ||
|
||
public ArrayList<SearchResult> retrieveDocuments(String query) throws Exception { | ||
ArrayList<SearchResult> resultL = new ArrayList<SearchResult>(); | ||
query = query.trim(); | ||
if (query.isEmpty()) return resultL; | ||
|
||
String requestURL = BingSearcherUtil.BuildRequest(query, mResNum); | ||
|
||
System.out.println("Bing Search : " + query); | ||
BingSearcherUtil.getResults(mAccountKey, | ||
mRetrievalCache, mCacheStorage, | ||
resultL, query, requestURL, mCacheId); | ||
|
||
System.out.println("Result size: " + resultL.size()); | ||
|
||
|
||
return resultL; | ||
} | ||
|
||
|
||
public static void main(String[] args) throws Exception { | ||
String accountId = args[0]; | ||
String cachePath = args[1]; | ||
String query = args[2]; | ||
|
||
BingSearcher web = new BingSearcher(accountId, cachePath, 50); | ||
|
||
System.out.println("Query: '" + query + "'"); | ||
System.out.println("Cache path: " + cachePath); | ||
|
||
ArrayList<SearchResult> res = web.retrieveDocuments(query); | ||
|
||
for (int i = 0; i < res.size(); ++i) { | ||
SearchResult o = res.get(i); | ||
System.out.println(i + " " + o.getDocID() + " " + o.getAnswer()); | ||
} | ||
} | ||
|
||
} |
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