Example #1
0
    def _search_sep(entity, entity2):
        # Build search string
        if entity2 is None:
            searchstr = c.entity.web_search_string()
            c.sep_searchstr = quote_plus(searchstr.encode("utf8"))
        else:
            searchstr = entity.web_search_string() + " + " + entity2.web_search_string()
            c.sep_searchstr = quote_plus(searchstr.encode("utf8"))

        # Put together URL string
        url = "http://plato.stanford.edu/cgi-bin/search/xmlSearcher.py?query=" + c.sep_searchstr

        # Get results and parse the XML
        results = multi_get([url])[0][1]
        json = None
        if results:
            tree = ET.ElementTree(ET.fromstring(results))
            root = tree.getroot()
            json = []
            for element in root.getiterator("{http://a9.com/-/spec/opensearch/1.1/}Item"):
                dict = {}
                for iter in element.getiterator("{http://a9.com/-/spec/opensearch/1.1/}Text"):
                    dict["Text"] = iter.text
                for iter in element.getiterator("{http://a9.com/-/spec/opensearch/1.1/}LongDescription"):
                    dict["LongDescription"] = iter.text
                for iter in element.getiterator("{http://a9.com/-/spec/opensearch/1.1/}Location"):
                    dict["URL"] = "http://plato.stanford.edu/entries/%s/" % iter.text
                for iter in element.getiterator("{http://a9.com/-/spec/opensearch/1.1/}Location"):
                    dict["Location"] = iter.text
                json.append(dict)

        return json
Example #2
0
    def missing_entity_search(self, query):
        query = quote_plus(query)
        url = "http://plato.stanford.edu/cgi-bin/search/xmlSearcher.py?query=" + query

        results = multi_get([url])[0][1]
        json = None
        values_dict = []
        if results:
            tree = ET.ElementTree(ET.fromstring(results))
            root = tree.getroot()
            json = []
            for element in root.getiterator("{http://a9.com/-/spec/opensearch/1.1/}Item"):
                dict = {}
                for iter in element.getiterator("{http://a9.com/-/spec/opensearch/1.1/}Location"):
                    dict["Location"] = iter.text
                json.append(dict)

            for j in range(len(json)):
                for key, value in json[j].iteritems():
                    values_dict.append(value)

        entities = Session.query(Entity).filter(Entity.sep_dir.in_(values_dict)).all()
        entities.sort(key=lambda entity: values_dict.index(entity.sep_dir))
        # raise Exception
        return entities
Example #3
0
    def _search_noesis(entity, entity2):
        # Concatenate search strings for each entity
        if entity2 is None:
            searchstr = c.entity.web_search_string()
            c.noesis_searchstr = quote_plus(searchstr.encode("utf8"))
        else:
            searchstr = entity.web_search_string() + " " + entity2.web_search_string()
            c.noesis_searchstr = quote_plus(searchstr.encode("utf8"))

        # Put together URL string
        api_key = "AIzaSyAd7fxJRf5Yj1ehBQAco72qqBSK1l0_p7c"
        c.noesis_cx = "001558599338650237094:d3zzyouyz0s"
        url = (
            "https://www.googleapis.com/customsearch/v1?"
            + "key="
            + api_key
            + "&cx="
            + c.noesis_cx
            + "&q="
            + c.noesis_searchstr
        )

        # Get results and parse into json
        results = multi_get([url])[0][1]
        json = simplejson.loads(results) if results else None
        return json
Example #4
0
    def _search_sep(entity, entity2):
        # Build search string
        if entity2 is None:
            searchstr = c.entity.web_search_string()
            c.sep_searchstr = quote_plus(searchstr.encode('utf8'))
        else:
            searchstr = entity.web_search_string() + " + " + \
                        entity2.web_search_string()
            c.sep_searchstr = quote_plus(searchstr.encode('utf8'))

        # Put together URL string
        url = "http://plato.stanford.edu/search/searcher.py?query=" + \
              c.sep_searchstr

        results = multi_get([url])[0][1]
        json = None
        if results:
            soup = BeautifulSoup(results, 'html.parser')
            divs = soup.findAll('div', {'class': 'result_listing'})
            json = []
            for div in divs:
                dict = {}
                dict['Text'] = div.find('a', {'class': 'l'}).contents
                dict['LongDescription'] = div.find('div', {'class': 'result_snippet'}).contents
                del dict['LongDescription'][-2:-1]
                dict['URL'] = div.find('a', {'class', 'l'})['href']
                dict['Location'] = 'test'
                json.append(dict)

        return json
Example #5
0
    def missing_entity_search(self, query):
        query = quote_plus(query)
        url = 'http://plato.stanford.edu/cgi-bin/search/xmlSearcher.py?query=' + \
            query
        
        results = multi_get([url])[0][1]
        json = None
        values_dict = []
        if results:
            tree = ET.ElementTree(ET.fromstring(results))
            root = tree.getroot()
            json = []
            for element in root.getiterator('{http://a9.com/-/spec/opensearch/1.1/}Item'):
                dict = {}
                for iter in element.getiterator('{http://a9.com/-/spec/opensearch/1.1/}Location'):
                    dict['Location'] = iter.text
                json.append(dict)

            for j in range(len(json)):
                for key,value in json[j].iteritems():
                    values_dict.append(value)
            
        
        entities = Session.query(Entity).filter(Entity.sep_dir.in_(values_dict)).all()
        entities.sort(key = lambda entity: values_dict.index(entity.sep_dir))
        #raise Exception
        return entities
Example #6
0
    def _search_bing(entity, entity2):
        # Concatenate search strings for each entity
        if entity2 is None:
            searchstr = c.entity.web_search_string()
            c.bing_searchstr = quote_plus(searchstr.encode("utf8"))
        else:
            searchstr = entity.web_search_string() + " " + entity2.web_search_string()
            c.bing_searchstr = quote_plus(searchstr.encode("utf8"))

        # Put together URL string
        api_key = "34B53247AE710D6C3F5AFB35100F396E780C2CC4"
        url = (
            "http://api.search.live.net/json.aspx" + "?Appid=" + api_key + "&query=" + c.bing_searchstr + "&sources=web"
        )

        # Get results and parse into json
        results = multi_get([url])[0][1]
        json = simplejson.loads(results) if results else None
        return json
Example #7
0
    def _search_bing(entity, entity2):
        # Concatenate search strings for each entity
        if entity2 is None:
            searchstr = c.entity.web_search_string()
            c.bing_searchstr = quote_plus(searchstr.encode('utf8'))
        else:
            searchstr = entity.web_search_string() + " " + \
                        entity2.web_search_string()
            c.bing_searchstr = quote_plus(searchstr.encode('utf8'))

        # Put together URL string
        api_key = "34B53247AE710D6C3F5AFB35100F396E780C2CC4"
        url = "http://api.search.live.net/json.aspx" + \
              "?Appid=" + api_key  + "&query=" + \
              c.bing_searchstr + "&sources=web"

        # Get results and parse into json
        results = multi_get([url])[0][1]
        json = simplejson.loads(results) if results else None
        return json
Example #8
0
    def _search_sep(entity, entity2):
        # Build search string
        if entity2 is None:
            searchstr = c.entity.web_search_string()
            c.sep_searchstr = quote_plus(searchstr.encode('utf8'))
        else:
            searchstr = entity.web_search_string() + " + " + \
                        entity2.web_search_string()
            c.sep_searchstr = quote_plus(searchstr.encode('utf8'))

        # Put together URL string
        url = "http://plato.stanford.edu/cgi-bin/search/xmlSearcher.py?query=" + \
              c.sep_searchstr

        # Get results and parse the XML
        results = multi_get([url])[0][1]
        json = None
        if results:
            tree = ET.ElementTree(ET.fromstring(results))
            root = tree.getroot()
            json = []
            for element in root.getiterator(
                    '{http://a9.com/-/spec/opensearch/1.1/}Item'):
                dict = {}
                for iter in element.getiterator(
                        '{http://a9.com/-/spec/opensearch/1.1/}Text'):
                    dict['Text'] = iter.text
                for iter in element.getiterator(
                        '{http://a9.com/-/spec/opensearch/1.1/}LongDescription'
                ):
                    dict['LongDescription'] = iter.text
                for iter in element.getiterator(
                        '{http://a9.com/-/spec/opensearch/1.1/}Location'):
                    dict[
                        'URL'] = 'http://plato.stanford.edu/entries/%s/' % iter.text
                for iter in element.getiterator(
                        '{http://a9.com/-/spec/opensearch/1.1/}Location'):
                    dict['Location'] = iter.text
                json.append(dict)

        return json
Example #9
0
    def _search_noesis(entity, entity2):
        # Concatenate search strings for each entity
        if entity2 is None:
            searchstr = c.entity.web_search_string()
            c.noesis_searchstr = quote_plus(searchstr.encode('utf8'))
        else:
            searchstr = entity.web_search_string() + " " + \
                        entity2.web_search_string()
            c.noesis_searchstr = quote_plus(searchstr.encode('utf8'))

        # Put together URL string
        api_key = "AIzaSyAd7fxJRf5Yj1ehBQAco72qqBSK1l0_p7c"
        c.noesis_cx = "001558599338650237094:d3zzyouyz0s"
        url = "https://www.googleapis.com/customsearch/v1?" + \
              "key=" + api_key + "&cx=" + c.noesis_cx + \
              "&q=" + c.noesis_searchstr

        # Get results and parse into json
        results = multi_get([url])[0][1]
        json = simplejson.loads(results) if results else None
        return json