From 29e19df431e4837ad6a840e8d6a6cc3f5f6b37e3 Mon Sep 17 00:00:00 2001 From: Lukas Moertl Date: Thu, 2 Nov 2023 13:03:45 +0100 Subject: [PATCH] use new SketchEngine. Still errors (due to slightly different results) actual login request lint fixes, --- src/components/Search/Search.vue | 4 +- src/composables/useAPIs.ts | 4 ++ src/composables/useWordlist.ts | 2 +- src/pages/login.vue | 5 ++- src/stores/auth.ts | 13 +++++-- src/stores/corpora.ts | 64 +++++++++++++++++++------------- src/types/corporaResponse.d.ts | 51 +++++++++++++++++++++++++ src/types/query.d.ts | 7 ---- 8 files changed, 109 insertions(+), 41 deletions(-) create mode 100644 src/types/corporaResponse.d.ts diff --git a/src/components/Search/Search.vue b/src/components/Search/Search.vue index 61a33c0..9e06a05 100644 --- a/src/components/Search/Search.vue +++ b/src/components/Search/Search.vue @@ -15,7 +15,7 @@ const CORPUS_QUERY_TYPES = [ { value: "word", description: "Word Search" }, ]; -// const { getYearlyFrequencies } = useYearlyFrequenciesSearch(); +const { getYearlyFrequencies } = useYearlyFrequenciesSearch(); const { getWordFormFrequencies } = useWordFormsSearch(); const { getMediaSourceFrequencies } = useMediaSourceSearch(); const { getRegionsFrequencies } = useRegionsSearch(); @@ -26,7 +26,7 @@ async function addQuery() { // newSelectedType.value = "word"; newUserInput.value = ""; - // await getYearlyFrequencies(addedQuery); + await getYearlyFrequencies(addedQuery); await getWordFormFrequencies(addedQuery); await getMediaSourceFrequencies(addedQuery); await getRegionsFrequencies(addedQuery); diff --git a/src/composables/useAPIs.ts b/src/composables/useAPIs.ts index 2810c86..228d71a 100644 --- a/src/composables/useAPIs.ts +++ b/src/composables/useAPIs.ts @@ -5,6 +5,9 @@ export function useAPIs() { const BASE_URL = config.public.apiBaseUrl; + // run.cgi/corpora + const CORPORA_LIST_URL = `${BASE_URL}/run.cgi/corpora`; + // https://corpsum-proxy.acdh-dev.oeaw.ac.at/run.cgi/corp_info?corpname=amc_3.2;subcorpora=1;format=json const SUB_CORPUS_URL = `${BASE_URL}/run.cgi/corp_info`; // params: { @@ -66,5 +69,6 @@ export function useAPIs() { WORDLIST_URL, VIEWSATTRSX_URL, SOURCES_URL, + CORPORA_LIST_URL, }; } diff --git a/src/composables/useWordlist.ts b/src/composables/useWordlist.ts index c87db9b..6496d64 100644 --- a/src/composables/useWordlist.ts +++ b/src/composables/useWordlist.ts @@ -23,7 +23,7 @@ export function useWordlist() { // todo adapt to weird format everything under corpname? const { data: response } = await authenticatedFetch(WORDLIST_URL, { params: { - corpname: selectedCorpus.value.id, + corpname: selectedCorpus.value.corpname, wlmaxitems: 1000, wlattr: "doc.docsrc", wlminfreq: 1, diff --git a/src/pages/login.vue b/src/pages/login.vue index 7ebb7ed..49a884f 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -7,8 +7,9 @@ const auth = useAuth(); const username = ref(""); const password = ref(""); -function login() { - if (!auth.login(username.value, password.value)) return alert("Username or Password wrong"); +async function login() { + if (!(await auth.login(username.value, password.value))) + return alert("Username or Password wrong"); } diff --git a/src/stores/auth.ts b/src/stores/auth.ts index 718ed13..7b4ae40 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -1,17 +1,24 @@ import { defineStore } from "pinia"; +import { useCorporaStore } from "./corpora"; + export const useAuth = defineStore( "auth", () => { const username = ref(""); const basicAuthToken = ref(""); - function login(_username: string, password: string) { + async function login(_username: string, password: string) { // todo actual login implementation if (_username) { + basicAuthToken.value = btoa(`${_username}:${password}`); + const copora = useCorporaStore(); + const corpora = await copora.fetchCorpora(); + if (!corpora) { + basicAuthToken.value = ""; + return false; + } username.value = _username; - - basicAuthToken.value = btoa(`${username.value}:${password}`); return true; } return false; diff --git a/src/stores/corpora.ts b/src/stores/corpora.ts index b79f73a..c2f245d 100644 --- a/src/stores/corpora.ts +++ b/src/stores/corpora.ts @@ -25,28 +25,42 @@ export type usedYear = export const useCorporaStore = defineStore( "corpora", () => { - const corpora: Ref> = ref([ - { - name: "Corpus: AMC 3.2", - id: "amc_3.2", - description: "The latest and full Austrian Media Corpus", - }, - { - name: "Corpus: AMC 60M", - id: "amc_60M", - description: "A 60M token sample of Austrian Media Corpus", - }, - { - name: "Corpus: AMC Demo", - id: "amc3_demo", - description: "A limited-size demo of Austrian Media Corpus", - }, - { - name: "Corpus: wrdiarium02.1", - id: "wrdiarium02.1", - description: "Wienerisches Diarium 02.1", - }, - ]); + const { SUB_CORPUS_URL, CORPORA_LIST_URL } = useAPIs(); + const { authenticatedFetch } = useAuthenticatedFetch(); + + const corpora: Ref> = ref([]); + + async function fetchCorpora() { + // console.log("in fetchCorpora", CORPORA_LIST_URL); + const { data } = await authenticatedFetch(CORPORA_LIST_URL, {}); + // console.log("corpfetch ", { data: data.value, error: error.value }); + if (!data.value) return false; + const corporaInfo = data.value as CorporaInfo; + corpora.value = corporaInfo.data; + return true; + } + // const corpora: Ref> = ref([ + // { + // name: "Corpus: AMC 3.2", + // id: "amc_3.2", + // description: "The latest and full Austrian Media Corpus", + // }, + // { + // name: "Corpus: AMC 60M", + // id: "amc_60M", + // description: "A 60M token sample of Austrian Media Corpus", + // }, + // { + // name: "Corpus: AMC Demo", + // id: "amc3_demo", + // description: "A limited-size demo of Austrian Media Corpus", + // }, + // { + // name: "Corpus: wrdiarium02.1", + // id: "wrdiarium02.1", + // description: "Wienerisches Diarium 02.1", + // }, + // ]); const selectedCorpus: Ref = ref(null); const subCorpora: Ref> = ref([]); @@ -76,9 +90,6 @@ export const useCorporaStore = defineStore( 2022: 5, } as Record, }); - - const { SUB_CORPUS_URL } = useAPIs(); - const { authenticatedFetch } = useAuthenticatedFetch(); // auto-fetch subcorpora when selectedCorpus changes watch(selectedCorpus, async (before, after) => { if (!after || before === after) return; //console.log("no change") @@ -89,7 +100,7 @@ export const useCorporaStore = defineStore( if (!selectedCorpus.value) return console.error("no corpus selected"); const { data: _subCorpora, error } = await authenticatedFetch(SUB_CORPUS_URL, { params: { - corpname: selectedCorpus.value.id, + corpname: selectedCorpus.value.corpname, subcorpora: 1, format: "json", }, @@ -113,6 +124,7 @@ export const useCorporaStore = defineStore( return { corpora, + fetchCorpora, subCorpora, selectedCorpus, selectedSubCorpus, diff --git a/src/types/corporaResponse.d.ts b/src/types/corporaResponse.d.ts new file mode 100644 index 0000000..9ba8afb --- /dev/null +++ b/src/types/corporaResponse.d.ts @@ -0,0 +1,51 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +interface CorporaInfo { + data: Array; + api_version: string; + manatee_version: string; + request: any; +} + +interface Corpus { + id?: any; + owner_id?: any; + owner_name?: any; + tagset_id?: any; + sketch_grammar_id?: any; + term_grammar_id?: any; + _is_sgdev: boolean; + is_featured: boolean; + access_on_demand: boolean; + terms_of_use?: any; + sort_to_end?: any; + tags: Array; + created?: any; + needs_recompiling: boolean; + user_can_read: boolean; + user_can_upload: boolean; + user_can_manage: boolean; + is_shared: boolean; + is_error_corpus: boolean; + corpname: string; + language_id: string; + language_name: string; + sizes: Sizes; + compilation_status: string; + new_version: string; + name: string; + info: string; + wsdef: string; + termdef: string; + diachronic: boolean; + aligned: Array; + docstructure: string; +} + +interface Sizes { + tokencount: string; + wordcount: string; + doccount: string; + parcount: string; + sentcount: string; + normsum?: string; +} diff --git a/src/types/query.d.ts b/src/types/query.d.ts index 87b9c77..2844951 100644 --- a/src/types/query.d.ts +++ b/src/types/query.d.ts @@ -57,10 +57,3 @@ interface SubCorpus { words: number; n: string; } - -// structure taken from old project (hardcoded) -interface Corpus { - id: string; - name: string; - description: string; -}