diff --git a/intern/ude_organization/content_extractor/content_extractor.py b/intern/ude_organization/content_extractor/content_extractor.py index 72430b3d..4e3b0ed2 100644 --- a/intern/ude_organization/content_extractor/content_extractor.py +++ b/intern/ude_organization/content_extractor/content_extractor.py @@ -554,7 +554,7 @@ if __name__ == '__main__': "bool":{ "must":{ "match_phrase": { - "uri": url + "sources": url } }, } diff --git a/intern/ude_organization/content_extractor/content_extractor_pydantic.py b/intern/ude_organization/content_extractor/content_extractor_pydantic.py index 5dd6cf1e..c3769373 100644 --- a/intern/ude_organization/content_extractor/content_extractor_pydantic.py +++ b/intern/ude_organization/content_extractor/content_extractor_pydantic.py @@ -50,12 +50,12 @@ class News(BaseModel): result:List[NewsItem] -es_home = Elasticsearch('http://localhost:9200', basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), request_timeout=60, max_retries=5, retry_on_timeout=True) +#es = Elasticsearch('http://localhost:9200', basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), request_timeout=60, max_retries=5, retry_on_timeout=True) es = Elasticsearch('https://inse.nes.uni-due.de:443/elastic', basic_auth=('elastic', 'RLldUaJgbGeoqd3KCX3p'), request_timeout=60, max_retries=5, retry_on_timeout=True) ude_organization_categorized = "ude_organization_categorized" -new_index_name = "testing_structure" +new_index_name = "ude_organization_content" total_succeeds = 0 total_failures = 0 @@ -550,8 +550,8 @@ def check_elastic_status(index_name): } try: - if not es_home.indices.exists(index=index_name): - es_home.indices.create(index=index_name, mappings=mappings, settings=settings) + if not es.indices.exists(index=index_name): + es.indices.create(index=index_name, mappings=mappings, settings=settings) print(f"INDEX {index_name} created...") else: print(f"INDEX {index_name} already exists...") @@ -582,9 +582,9 @@ if __name__ == '__main__': #get urls to work with uploaded_urls = [org['uri'] for org in uploaded_orgs] print('Uploaded orgs:',uploaded_orgs) - hierarchy_orgs = get_urls(path_to_hierarchy=sys.argv[1])[50:60] + hierarchy_orgs = get_urls(path_to_hierarchy=sys.argv[1]) urls = [url for url in hierarchy_orgs if url not in uploaded_urls] - + #extracting content failedPages = [] if (check_elastic_status(new_index_name)): @@ -596,7 +596,7 @@ if __name__ == '__main__': "bool":{ "must":{ "match_phrase": { - "uri": url + "sources": url } }, } @@ -659,7 +659,7 @@ if __name__ == '__main__': print(f'Organization data cleaned. Staff: {len(organization["staff"])}, Projects: {len(organization["projects"])}, News: {len(organization["news"])}') #print('Organization below:') #print(organization) - es_home.index(index=new_index_name, document=organization) + es.index(index=new_index_name, document=organization) print('Organization uploaded.') uploaded_orgs.append({"uri":organization['uri']}) diff --git a/intern/ude_organization/extract_ude_content_keywords/extract_ude_content_keywords.py b/intern/ude_organization/extract_ude_content_keywords/extract_ude_content_keywords.py index aef1e8d2..ccd62f2a 100644 --- a/intern/ude_organization/extract_ude_content_keywords/extract_ude_content_keywords.py +++ b/intern/ude_organization/extract_ude_content_keywords/extract_ude_content_keywords.py @@ -13,7 +13,7 @@ from pydantic import BaseModel, model_validator import pydantic from typing import List -#es_home = Elasticsearch('http://localhost:9200', basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), request_timeout=60, max_retries=5, retry_on_timeout=True) +#es = Elasticsearch('http://localhost:9200', basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), request_timeout=60, max_retries=5, retry_on_timeout=True) es = Elasticsearch('https://inse.nes.uni-due.de:443/elastic', basic_auth=('elastic', 'RLldUaJgbGeoqd3KCX3p'), request_timeout=60, max_retries=5, retry_on_timeout=True) URL = "https://project.nes.uni-due.de/llm1/v1/chat/completions" diff --git a/intern/ude_organization/upload_ude_pages.ipynb b/intern/ude_organization/upload_ude_pages.ipynb deleted file mode 100644 index 4dd8548f..00000000 --- a/intern/ude_organization/upload_ude_pages.ipynb +++ /dev/null @@ -1,522 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "INDEX ude_pages already exists...\n", - "+++++++DIR: warc_zips\\ude-20240920104108-00000-voxel.warc.gz\n", - "Searching file warc_zips\\ude-20240920104108-00000-voxel.warc.gz\n", - "text/plain\n", - "b'# robots.txt file\\n# Bans all robots from listed directories\\n\\n#User-agent: *\\n#Disallow: /~ht0209/lab2014/\\n#Disallow: /~bi0058/\\n#Disallow: /cms/zs-2001/htdocs/\\n#Disallow: /imp/zs-2001/htdocs/\\n\\nUser-agent: bingbot\\n#Disallow: /~ht0209/lab2014/\\n#Disallow: /~bi0058/\\nCrawl-delay: 10\\n\\nUser-agent: GPTBot\\nDisallow: /\\n'\n", - "\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n", - "#######################################\n", - "persisting...\n" - ] - } - ], - "source": [ - "import warcio\n", - "import sys\n", - "import bs4\n", - "import langdetect \n", - "import trafilatura\n", - "import os\n", - "import json\n", - "import re\n", - "import time\n", - "import html\n", - "from elasticsearch import Elasticsearch\n", - "import yake\n", - "#inse elastic instance\n", - "#es = Elasticsearch('https://inse.nes.uni-due.de:443/elastic', basic_auth=('elastic', 'RLldUaJgbGeoqd3KCX3p'), request_timeout=60, max_retries=5, retry_on_timeout=True)\n", - "#es = Elasticsearch({'host':'localhost', 'port': 9200, 'scheme': 'http'})\n", - "es = Elasticsearch('http://localhost:9200',verify_certs=True, basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), max_retries=5, retry_on_timeout=True)\n", - "\n", - "\n", - "\n", - "index_name = \"ude_pages\"\n", - "\n", - "\n", - "def check_elastic_status():\n", - " if not es.ping():\n", - " print(\"Elasticsearch connection not found\")\n", - " return False\n", - " \n", - " #if es.indices.exists(index=index_name):\n", - " # es.indices.delete(index=index_name, ignore=[400, 404])\n", - " \n", - " settings = {\n", - " \"analysis\": {\n", - " \"analyzer\": {\n", - " \"customanalyzer\": {\n", - " \"type\": \"custom\",\n", - " \"tokenizer\": \"standard\",\n", - " \"filter\": [\n", - " \"lowercase\",\n", - " \"asciifolding\"\n", - " ]\n", - " }\n", - " }\n", - " }\n", - " }\n", - " mappings = {\n", - " \n", - " \"properties\": {\n", - " \"uri\": {\n", - " \"type\": \"text\",\n", - " \"fields\": {\n", - " \"keyword\": { \n", - " \"type\": \"keyword\"\n", - " }\n", - " }\n", - " },\n", - " \"domain\": {\n", - " \"type\": \"keyword\"\n", - " },\n", - " \"subdomain\": {\n", - " \"type\": \"keyword\"\n", - " }, \n", - " \"path\": {\n", - " \"type\": \"text\",\n", - " \"fields\": {\n", - " \"keyword\": { \n", - " \"type\": \"keyword\"\n", - " }\n", - " }\n", - " },\n", - " \"query\": {\n", - " \"type\": \"text\",\n", - " \"fields\": {\n", - " \"keyword\": { \n", - " \"type\": \"keyword\"\n", - " }\n", - " }\n", - " },\n", - " \"host\": {\n", - " \"type\": \"keyword\"\n", - " },\n", - " \"body\": {\n", - " \"type\": \"text\",\n", - " \"analyzer\": \"customanalyzer\",\n", - " \"search_analyzer\": \"customanalyzer\"\n", - " },\n", - " \"lang\": {\n", - " \"type\": \"keyword\"\n", - " },\n", - " \"tags\": {\n", - " \"type\": \"nested\",\n", - " \"properties\": {\n", - " \"value\": { \"type\": \"keyword\" },\n", - " \"score\": { \"type\": \"double\" }\n", - " }\n", - " },\n", - " }\n", - "\n", - "\n", - " }\n", - " try:\n", - " if not es.indices.exists(index=index_name):\n", - " es.indices.create(index=index_name, mappings=mappings, settings=settings)\n", - " print(f\"INDEX {index_name} created...\")\n", - " else:\n", - " print(f\"INDEX {index_name} already exists...\")\n", - " \n", - " \n", - " except Exception as e:\n", - " print(\"failed to create index mapping\") \n", - " print(e) \n", - " return False\n", - " \n", - " return True\n", - "\n", - "def getGroups(match):\n", - " uri={'protocol':\"\",\n", - " 'subdomain':\"\",\n", - " 'domain':\"\",\n", - " 'port':\"\",\n", - " 'path':\"\",\n", - " 'query':\"\"}\n", - " if match:\n", - " uri['protocol'] = match.group(1) if match.group(1) else \"\"\n", - " uri['subdomain'] = match.group(2) if match.group(2) else \"\"\n", - " uri['domain'] = match.group(3) if match.group(3) else \"\"\n", - " uri['port'] = match.group(4) if match.group(4) else \"\"\n", - " uri['path'] = match.group(5) if match.group(5) else \"\"\n", - " uri['query'] = match.group(6) if match.group(6) else \"\"\n", - "\n", - " return uri\n", - "\n", - " \n", - "def process_file(filename,total_records):\n", - " print(\"Searching file\", filename)\n", - " records = 0\n", - " bodies = []\n", - " regex_for_link_parts = r'^(\\w+):\\/\\/(?:((?:[^\\/:.]+\\.)+))?([^\\/:.]+(?:\\.[^\\/:.]+)+)(?::(\\d+))?(\\/[^?#]*)?(\\?[^#]*)?(#.*)?$'\n", - " with open(filename, 'rb') as stream:\n", - " for record in warcio.ArchiveIterator(stream):\n", - " if total_records < 100000:\n", - " if record.rec_type == 'response':\n", - " content_type = record.http_headers.get_header('Content-Type')\n", - " if not bool(content_type):\n", - " continue\n", - " if 'text/html' in content_type.lower():\n", - " tokens = content_type.split(\";\")\n", - " encoding = \"iso-8859-1\"\n", - " for token in tokens:\n", - " trimmed = token.strip()\n", - " if trimmed.startswith(\"charset=\"):\n", - " encoding = trimmed[8:].lower()\n", - "\n", - " try:\n", - " decoded = record.content_stream().read().decode(encoding)\n", - " except:\n", - " continue\n", - " \n", - " text = trafilatura.extract(decoded, output_format=\"txt\")\n", - " try:\n", - " lang = langdetect.detect(text)\n", - " except:\n", - " lang = ''\n", - " try:\n", - " title = html.unescape(re.search(r\"