def get_total_entries_by_yr(year):
    return fc.search(lookfor="",
                     search_type=fst.Subject,
                     fields=["year"],
                     filters=[("main_date_str:" + str(year))],
                     page=1,
                     limit=100)['resultCount']
def get_response(pg, search_query, year):
    return fc.search(lookfor=search_query,
                     search_type=fst.Subject,
                     fields=["title", "buildings", "subjects"],
                     filters=[("main_date_str:" + str(year))],
                     facets=["author"],
                     page=pg,
                     limit=100)
def get_tree(year):
    finna = FinnaClient()
    sk = SkosmosClient()
    records = finna_search(year, finna)
    chains = [get_keyword_chain(x.subject, sk) for x in records]
    chains = [x for x in chains if x is not None]
    trees = [create_tree(x) for x in chains]
    return join_trees(trees)
def finna_search(searchwords, filters = [], limit = 10):
    res = []
    resultcount = 0
    finna = FinnaClient()
    for word in searchwords:
        result = finna.search(word,
                              #search_type=FinnaSearchType.Author,
                              fields=['title','nonPresenterAuthors','id','formats','subjects','year','languages','primaryAuthors'],
                              filters=filters, 
                              #sort=FinnaSortMethod.main_date_str_desc,
                              limit=limit)
        res.extend(result["records"])
        resultcount += result['resultCount']
    
    results = []
    for item in res:
        if item not in results:
            item['url'] = "https://www.finna.fi/Record/"+item['id']
            if 'formats' in item and len(item['formats']):
                item['formats'] = item['formats'][0]
            else:
                item['formats'] = {'translated': ''}
            results.append(item)
    # from pprint import pprint
    # pprint(results[0])
    # {'formats': [{'translated': 'Kirja', 'value': '0/Book/'},
    #              {'translated': 'Kirja', 'value': '1/Book/Book/'}],
    #  'id': 'alli.313062',
    #  'languages': ['eng'],
    #  'nonPresenterAuthors': [{'name': 'Koolhaas, Rem'}],
    #  'primaryAuthors': [],
    #  'subjects': [],
    #  'title': 'Content',
    #  'url': 'https://www.finna.fi/Record/alli.313062',
    #  'year': '2004'}

    return results
示例#5
0
from finna_client import FinnaClient
finna = FinnaClient()
results = finna.search("bicycle", limit=5)
for rec in results['records']:
    print(rec['title'])

from annif_client import AnnifClient
annif = AnnifClient()
results = annif.analyze(project_id='yso-en',
                        text="The quick brown fox",
                        limit=5)
for result in results:
    print(result)
 def __init__(self):
     self.client = FinnaClient()
示例#7
0
#!/usr/bin/env python

import json
from http.server import BaseHTTPRequestHandler, HTTPServer

from finna_client import FinnaClient

from places import Places
from search import paged_search, vectorized

finna = FinnaClient()
places = Places('yso-paikat-skos.rdf')
cache = {}


class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        if 'api' in self.path:
            subject = self.path.strip().split('/')[2]
            print(subject)
            if not subject in cache:
                results = paged_search(finna, subject, places)
                vector = vectorized(results, places)
                cache[subject] = vector
            vector = cache[subject]

            #geojson = {"type": "Feature", "geometry": { "type": "Polygon", "coordinates": vector}}

            self.send_response(200)

            self.send_header('Content-type', 'text/json')
示例#8
0
from finna_client import FinnaClient, FinnaSearchType, FinnaSortMethod
import urllib
from PIL import Image

import requests
from io import BytesIO
import os

LIMIT = 100
SUBJECT = 'soutuveneet'
row_path = 'data/rowboats'

os.mkdirs(row_paths)
os.mkdirs('checkpoints')

finna = FinnaClient()
result = finna.search(SUBJECT,
                      search_type=FinnaSearchType.Subject,
                      limit=0,
                      filters=['format:0/Image/', 'online_boolean:1'])

pages = result['resultCount'] // LIMIT

urls = []
for page in range(pages):
    result = finna.search(SUBJECT,
                          search_type=FinnaSearchType.Subject,
                          filters=['format:0/Image/', 'online_boolean:1'],
                          fields=['images'],
                          sort=FinnaSortMethod.main_date_str_asc,
                          limit=LIMIT,