Skip to content

Commit

Permalink
use new SketchEngine. Still errors (due to slightly different results)
Browse files Browse the repository at this point in the history
actual login request
lint fixes,
  • Loading branch information
lmoertl committed Nov 2, 2023
1 parent 4a8df87 commit 29e19df
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/components/Search/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/composables/useAPIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -66,5 +69,6 @@ export function useAPIs() {
WORDLIST_URL,
VIEWSATTRSX_URL,
SOURCES_URL,
CORPORA_LIST_URL,
};
}
2 changes: 1 addition & 1 deletion src/composables/useWordlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
</script>

Expand Down
13 changes: 10 additions & 3 deletions src/stores/auth.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
64 changes: 38 additions & 26 deletions src/stores/corpora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,42 @@ export type usedYear =
export const useCorporaStore = defineStore(
"corpora",
() => {
const corpora: Ref<Array<Corpus>> = 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<Array<Corpus>> = 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<Array<Corpus>> = 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<Corpus | null> = ref(null);
const subCorpora: Ref<Array<SubCorpus>> = ref([]);
Expand Down Expand Up @@ -76,9 +90,6 @@ export const useCorporaStore = defineStore(
2022: 5,
} as Record<usedYear, number>,
});

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")
Expand All @@ -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",
},
Expand All @@ -113,6 +124,7 @@ export const useCorporaStore = defineStore(

return {
corpora,
fetchCorpora,
subCorpora,
selectedCorpus,
selectedSubCorpus,
Expand Down
51 changes: 51 additions & 0 deletions src/types/corporaResponse.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
interface CorporaInfo {
data: Array<Corpus>;
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<any>;
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<any>;
docstructure: string;
}

interface Sizes {
tokencount: string;
wordcount: string;
doccount: string;
parcount: string;
sentcount: string;
normsum?: string;
}
7 changes: 0 additions & 7 deletions src/types/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,3 @@ interface SubCorpus {
words: number;
n: string;
}

// structure taken from old project (hardcoded)
interface Corpus {
id: string;
name: string;
description: string;
}

0 comments on commit 29e19df

Please sign in to comment.