mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-23 15:51:01 +08:00
Modify to make the system work, but just really slow & laggy even on a M1 Macbook :(
This commit is contained in:
parent
c66b9cde13
commit
d4904d18b8
@ -6,7 +6,6 @@ const props = defineProps<{
|
|||||||
}>();
|
}>();
|
||||||
import DraggableWindow from "~/components/DraggableWindow.vue";
|
import DraggableWindow from "~/components/DraggableWindow.vue";
|
||||||
const ffeed = ref();
|
const ffeed = ref();
|
||||||
const ass = ["健康2.0", "中天", "TVBS", "香港01", "ETtoday"];
|
|
||||||
import Button from "~/components/ui/button/Button.vue";
|
import Button from "~/components/ui/button/Button.vue";
|
||||||
const pending = ref();
|
const pending = ref();
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ScanEyeIcon } from "lucide-vue-next";
|
import { ScanEyeIcon, RefreshCcwIcon } from "lucide-vue-next";
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
@ -21,16 +21,26 @@ async function CheckKidUnfriendlyContent(title: string, words: any[]) {
|
|||||||
const emit = defineEmits(["close", "min", "restore"]);
|
const emit = defineEmits(["close", "min", "restore"]);
|
||||||
const staticid = computed(() => props.staticid);
|
const staticid = computed(() => props.staticid);
|
||||||
|
|
||||||
const pullTabsData = async () => {
|
|
||||||
const req = await fetch("/api/tabs");
|
|
||||||
const data = await req.json();
|
|
||||||
return data.data;
|
|
||||||
};
|
|
||||||
const contentArray = ref([]);
|
const contentArray = ref([]);
|
||||||
const errorr = ref(false);
|
const errorr = ref(false);
|
||||||
const switchTabs = ref(false);
|
const switchTabs = ref(false);
|
||||||
const tabs = ref([]);
|
const tabs = ref([]);
|
||||||
const primary = ref<string>("domestic");
|
const primary = ref<string>("domestic");
|
||||||
|
const canNotLoadTabUI = ref(false);
|
||||||
|
const pullTabsData = async () => {
|
||||||
|
try {
|
||||||
|
const req = await fetch("/api/tabs");
|
||||||
|
const data = await req.json();
|
||||||
|
if (data.error) {
|
||||||
|
canNotLoadTabUI.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return data.data;
|
||||||
|
} catch (e) {
|
||||||
|
canNotLoadTabUI.value = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const updateContent = async (url: string, tabAction: boolean) => {
|
const updateContent = async (url: string, tabAction: boolean) => {
|
||||||
if (tabAction === true) {
|
if (tabAction === true) {
|
||||||
@ -45,6 +55,7 @@ const updateContent = async (url: string, tabAction: boolean) => {
|
|||||||
switchTabs.value = false;
|
switchTabs.value = false;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
errorr.value = true;
|
errorr.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +90,7 @@ const checks = async (title: string) => {
|
|||||||
const wordss = await pullWord();
|
const wordss = await pullWord();
|
||||||
const result = await CheckKidUnfriendlyContent(title, wordss);
|
const result = await CheckKidUnfriendlyContent(title, wordss);
|
||||||
checkResults.value.set(title, result);
|
checkResults.value.set(title, result);
|
||||||
|
console.log(title);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
const getCheckResult = (title: string) => {
|
const getCheckResult = (title: string) => {
|
||||||
@ -88,20 +100,18 @@ watch(
|
|||||||
contentArray,
|
contentArray,
|
||||||
async (newContent) => {
|
async (newContent) => {
|
||||||
for (const item of newContent) {
|
for (const item of newContent) {
|
||||||
if (item.title) {
|
if (item.title && !switchTabs.value && item.contentType === 'GENERAL') {
|
||||||
await checks(item.title);
|
checks(item.title);
|
||||||
}
|
}
|
||||||
|
console.log(switchTabs.value);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
const findRel = (title: string) => {
|
|
||||||
return tf(title);
|
|
||||||
};
|
|
||||||
|
|
||||||
const tf = (text: string) => {
|
const tf = (text: string) => {
|
||||||
const words = text.toLowerCase().split("");
|
const words = text.toLowerCase().match(/[\u4e00-\u9fff]|[a-zA-Z0-9]+/g) || [];
|
||||||
// const words = text.toLowerCase().match(/[\u4e00-\u9fff]|[a-zA-Z0-9]+/g) || [];
|
|
||||||
|
|
||||||
const freqMap = new Map();
|
const freqMap = new Map();
|
||||||
|
|
||||||
@ -119,6 +129,40 @@ const tf = (text: string) => {
|
|||||||
return tfVector;
|
return tfVector;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const jaccardSimilarity = (v1: any, v2: any) => {
|
||||||
|
const k1 = new Set(Object.keys(v1))
|
||||||
|
const k2 = new Set(Object.keys(v2))
|
||||||
|
const intersection = new Set([...k1].filter(x => k2.has(x)));
|
||||||
|
const union = new Set([...k1, ...k2]);
|
||||||
|
return intersection.size / union.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
const findRel = (title: string) => {
|
||||||
|
const targetVector = tf(title);
|
||||||
|
const similarities = [];
|
||||||
|
|
||||||
|
for (const item of contentArray.value) {
|
||||||
|
if (item.title !== title && item.contentType === 'GENERAL') {
|
||||||
|
console.log(item.title);
|
||||||
|
const itemVector = tf(item.title);
|
||||||
|
console.log(itemVector);
|
||||||
|
const similarity = jaccardSimilarity(targetVector, itemVector);
|
||||||
|
console.log(similarity);
|
||||||
|
if (similarity > 0.1) {
|
||||||
|
similarities.push({
|
||||||
|
title: item.title,
|
||||||
|
similarity: similarity,
|
||||||
|
item: item
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.log(similarities);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return similarities
|
||||||
|
.sort((a, b) => b.similarity - a.similarity)
|
||||||
|
.slice(0, 3);
|
||||||
|
};
|
||||||
|
|
||||||
const openNews = (url: string) => {
|
const openNews = (url: string) => {
|
||||||
console.log(url);
|
console.log(url);
|
||||||
};
|
};
|
||||||
@ -138,11 +182,12 @@ const openPublisher = (text: string) => {};
|
|||||||
:class="
|
:class="
|
||||||
isPrimary(item.url, true) ? 'text-sky-600 text-bold' : 'text-black'
|
isPrimary(item.url, true) ? 'text-sky-600 text-bold' : 'text-black'
|
||||||
"
|
"
|
||||||
class=""
|
class="disabled:cursor-not-allowed"
|
||||||
:disabled="isPrimary(item.url, true)"
|
:disabled="isPrimary(item.url, true) || switchTabs"
|
||||||
>
|
>
|
||||||
<span>{{ item.text }}</span>
|
<span>{{ item.text }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button v-if="canNotLoadTabUI"><RefreshCcwIcon/></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Transition
|
<Transition
|
||||||
|
Loading…
x
Reference in New Issue
Block a user