예제 #1
0
def build_parameters(query, params):
    """ builds parameters dictionary to search by"""
    if not params:
        translator = Query_Language(identifier)
        params = translator.searcher_translator(query)
    all_words = getValue(params, 'all words')
    exact_phrase = getValue(params, 'exact phrase')
    exclude = getValue(params, 'exclude words')
    not_in = getValue(params, '-')
    if exclude and not_in:
        exclude += "+" + not_in
    elif not_in:
        exclude = not_in
    if exclude:
        params.update({"exclude words": [exclude]})
    artist = getValue(params, 'artist')
    keywords = getValue(params, 'title')
    accession_number = getValue(params, 'accession number')
    school = getValue(params, 'school')
    classification = getValue(params, 'classification')
    medium = getValue(params, 'medium')
    year1 = getValue(params, 'start date')
    year2 = getValue(params, 'end date')
    access = getValue(params, 'access')
    # build up the url
    url_base = BASE_ADVANCED_SEARCH_URL + "&all_words=" + all_words + "&exact_phrase=" + exact_phrase + "&exclude_words=" + exclude
    url_base += "&artist_last_name=" + artist + "&keywords_in_title=" + keywords + "&accession_num=" + accession_number
    url_base += "&school=" + school + "&classification=" + classification + "&medium=" + medium + "&year=" + year1 + "&year2=" + year2
    url_base += "&open_access=" + access
    # replace all whitespace from the parameters
    url_base = re.sub(" ", "+", url_base)
    return params, url_base
예제 #2
0
파일: nga.py 프로젝트: Blanko2/vic-mdid
def build_parameters(query, params):
    """ builds parameters dictionary to search by"""
    if not params:
        translator = Query_Language(identifier)
        params = translator.searcher_translator(query)
    all_words = getValue(params, 'all words')
    exact_phrase = getValue(params, 'exact phrase')
    exclude = getValue(params, 'exclude words')
    not_in = getValue(params,'-')
    if exclude and not_in:
        exclude += "+"+not_in
    elif not_in:
        exclude = not_in
    if exclude:
        params.update({"exclude words":[exclude]})
    artist = getValue(params, 'artist')
    keywords = getValue(params, 'title')
    accession_number = getValue(params, 'accession number')
    school = getValue(params, 'school')
    classification = getValue(params, 'classification')
    medium = getValue(params, 'medium')
    year1 = getValue(params, 'start date')
    year2 = getValue(params, 'end date')
    access = getValue(params, 'access')
    # build up the url
    url_base = BASE_ADVANCED_SEARCH_URL + "&all_words="+all_words + "&exact_phrase="+exact_phrase+ "&exclude_words="+exclude
    url_base += "&artist_last_name="+artist+"&keywords_in_title="+keywords + "&accession_num="+accession_number
    url_base += "&school="+school + "&classification="+classification + "&medium=" + medium + "&year="+year1 + "&year2="+year2
    url_base += "&open_access="+access
    # replace all whitespace from the parameters
    url_base = re.sub(" ", "+", url_base)
    return params,  url_base
def count(keyword):
    query_language = Query_Language(identifier)
    query_terms = query_language.searcher_translator(keyword)
    url = build_url(query_terms, 0, 1)
    raw_data = get_data(url)
    data, count, num_results = parse_data(raw_data)
    return count
def search(term, params, off, len):
    if DEBUG:
        print "CA Search"
    if not term and not params:
        return Result(0, 1), {}
    if not params:
        query_language = Query_Language(identifier)
        query_terms = query_language.searcher_translator(term)
        params = query_terms
    url = build_url(params, off, len)
    raw_data = get_data(url)
    data, count, num_results = parse_data(raw_data)
    nextOff = int(off) + int(num_results)
    result = Result(count, nextOff if nextOff < count else count)
    for i in data.keys():
        image = data[i]
        print image
        result.addImage(
            ResultImage(
                image["url"],
                image["thumb"],
                rebuild("" + image["name"] + ", by: " + image["artist"] + ". " + image["description"]),
                json.dumps(image),
            )
        )
    return result, {}
def count(keyword):
    query_language = Query_Language(identifier)
    query_terms = query_language.searcher_translator(keyword)
    url = build_url(query_terms, 0, 1)
    raw_data = get_data(url)
    data, count, num_results = parse_data(raw_data)
    return count
예제 #6
0
def build_URL(query, query_terms):
    if not query_terms:
        query_language = Query_Language(identifier)
        query_terms = query_language.searcher_translator(query)

    url = API_URL.replace("TROVE_KEY", TROVE_KEY)
    arg = empty_arg()
    url, arg = parse_trove_query(url, query_terms, arg)
    return url, arg
예제 #7
0
파일: trove.py 프로젝트: Blanko2/vic-mdid
def build_URL(query, query_terms):
    if not query_terms:
        query_language = Query_Language(identifier)
        query_terms = query_language.searcher_translator(query)    
    
    url = API_URL.replace("TROVE_KEY", TROVE_KEY)
    arg = empty_arg()
    url, arg = parse_trove_query(url, query_terms,arg)
    return url, arg
예제 #8
0
def build_URL(query, params):
    """ determines if the url should be simple or advanced and launches
    corresponding method"""
    if query and not params:
        ql = Query_Language(identifier)
        params = ql.searcher_translator(query)
    query, params = parse_gallica(params)
    if not query and not params:
        return None, get_empty_params()
    if query :
        return build_simple_url(query)
    return build_advanced_url(params)
예제 #9
0
파일: gallica.py 프로젝트: Blanko2/vic-mdid
def build_URL(query, params):
    """ determines if the url should be simple or advanced and launches
    corresponding method"""
    if query and not params:
        ql = Query_Language(identifier)
        
        
        params = ql.searcher_translator(query)
    query, params = parse_gallica(params)
    if not query and not params:
        return None, get_empty_params()
    if query :
        return build_simple_url(query)
    return build_advanced_url(params)
예제 #10
0
def search(term, params, off, len):
    if DEBUG:
        print "CA Search"
    if not term and not params:
        return Result(0, 1), {}
    if not params:
        query_language = Query_Language(identifier)
        query_terms = query_language.searcher_translator(term)
        params = query_terms
    url = build_url(params, off, len)
    raw_data = get_data(url)
    data, count, num_results = parse_data(raw_data)
    nextOff = int(off)+int(num_results)
    result = Result(count, nextOff if nextOff < count else count)
    for i in data.keys():
        image = data[i]
        print image
        result.addImage(ResultImage(image["url"], image['thumb'], rebuild(""+image['name']+", by: "+image['artist']+". "+image['description']), json.dumps(image)))
    return result, {}
예제 #11
0
def _translate_query(query):
    """ translates from universal query language to dnz query language """
    translator = Query_Language(identifier) 
    query_terms = translator.searcher_translator(query)
    return query_terms
예제 #12
0
def _translate_query(query):
    translator = Query_Language(identifier)
    query_terms = translator.searcher_translator(query)
    return query_terms
예제 #13
0
def _translate_query(query):
    """ translates from universal query language to dnz query language """
    translator = Query_Language(identifier)
    query_terms = translator.searcher_translator(query)
    return query_terms