---------------------------------DEV_THEO_2 06.01.2025-------------------------------
Added dataset llm. For testing llms approach.
How? 
1.Faculty urls from UDE, MUENSTER DORTMUND and other unis taken + institutes from UDE and MUE + chairs from UDE und MUE + OTHER URLS from Database
2.Extracted content from pages + headings + kind + label + pagedepth ...
3. Saved to llm_dataset.json



FURTHER LLM CLASSIFICATION RESULTS (FOR LLM_DATASET):
Purpose: again, use the main algorithm options(disambiguate, direct, indirect, meta, dynamic) and prediction of LLM.
Input: again, take page depth, headings and text of each page.

Output: evaluation results
<-------------------------------------LLAMA----------------------------------->
--------------------->FACULTIES:
Evaluation of LLaMa3
Faculties
all: 2997

wrong_labeled_format: 38

true_pos: 229
true_neg: 2393
false_pos: 327
false_neg: 10

precision: 0.4118705035971223
recall: 0.9581589958158996
f1_score: 0.5761006289308177

wrong_of_all: 1.2679346012679344
--------------------->INSTITUTES AND CHAIRS:
Evaluation of LLaMa3
Institutes and chairs
all: 2997

wrong_labeled_format: 43

true_pos: 756
true_neg: 1523
false_pos: 559
false_neg: 116

precision: 0.5749049429657794
recall: 0.8669724770642202
f1_score: 0.691358024691358

wrong_of_all: 1.434768101434768

#TODO how much INST and chairs? Not possible. The script should be executed again

<-------------------------------------GPT-4o-mini----------------------------------->
Evaluation of OPENAI
--------------------->FACULTIES:
all: 2995

wrong_labeled_format: 1

true_pos: 150
true_neg: 2694
false_pos: 61
false_neg: 89

precision: 0.7109004739336493
recall: 0.6276150627615062
f1_score: 0.6666666666666666

wrong_of_all: 0.0333889816360601
--------------------->INSTITUTES AND CHAIRS:
Evaluation of OPENAI
Institutes and chairs
all: 2994

wrong_labeled_format: 1

true_pos: 203
true_neg: 2018
false_pos: 93
false_neg: 679

precision: 0.6858108108108109
recall: 0.23015873015873015
f1_score: 0.34465195246179964

wrong_of_all: 0.033400133600534405


---------------------------------------Flan T5 for classifying pages added---------------------------
Purpose: again, use the main algorithm options(disambiguate, direct, indirect, meta, dynamic) and prediction of LLM.
Input: again, take page depth, headings and text of each page.

Output classification results:

RESULTS:
UDE
Evaluating ConceptType.FACULTY
  Predictions 10 Truth 12
  TP 8 FP 2 FN 4
  P 0.8 R 0.6666666666666666 F1 0.7272727272727272
Evaluating ConceptType.INSTITUTE
  Predictions 14 Truth 45
  TP 11 FP 3 FN 34
  P 0.7857142857142857 R 0.24444444444444444 F1 0.3728813559322034
Evaluating ConceptType.CHAIR
  Predictions 267 Truth 423
  TP 209 FP 40 FN 214
  P 0.8393574297188755 R 0.4940898345153664 F1 0.6220238095238095

MUENSTER:
Evaluating ConceptType.FACULTY
  Predictions 44 Truth 15
  TP 12 FP 26 FN 3
  P 0.3157894736842105 R 0.8 F1 0.45283018867924535
Evaluating ConceptType.INSTITUTE
  Predictions 151 Truth 135
  TP 94 FP 47 FN 41
  P 0.6666666666666666 R 0.6962962962962963 F1 0.6811594202898551
Evaluating ConceptType.CHAIR
  Predictions 384 Truth 428

  TP 233 FP 146 FN 195
  P 0.6147757255936676 R 0.544392523364486 F1 0.5774473358116482


--------------------------------->ANALYSIS.<---------------------------------------

Idea: use newly released REASONING for classifying university pages. Extract features from LLM explanation, count sentiment scores.

Pipeline -> create dataset from baseline -> classify content (is the content of the page is  a landing page(homepage) of a institute, research center, center, research group, department or chair'?) REASONING with certainty scores-
-> extract features from the REASONING output

1) Dataset created from baseline (each page has url, page depth, text, wrappet(true/false)
2)Classify content: questions asked to LLAMA:

search_type = 'faculty'  for FACULTIES
search_type = 'institute, research center, center, research group, department or chair' FOR INSTITUES/ CHAIRS
page_type = 'welcome page of the homepage'
    
question1 = f'Yes or no, is the following page the {page_type} of a {search_type} at an institute or university?\n\nPage:\n' + text
-> expected answer: yes/no
question2 = f'On a scale from 1 to 10 where 1 means low and 10 means high, how certain are you that the following page is OUTCOME the {page_type} of a {search_type} at an institute or university? Only return the number and do not provide an explanation.\n\Page:\n' + answer1 + text
-> expected answer: float value

question3 = f'Please explain why the following page is OUTCOME the {page_type} of a {search_type} at an institute or university.\n\nPage:\n' + answer1 + text
-> expected answer: explanation in text
question4 = 'Yes or no, is the following argumentation convincing?\n\nQuestion:\n' + question3 + '\n\nExplanation:\n' + answer3
-> expected answer: yes/no

3) Classify URL: questions asked to LLAMA
question1 = f"Yes or no, does this {url} look like it is pointing to a welcome page of a research group, department or chair?"
-> expected answer: yes/no

4)Extracting features

# With regular expression apture content in the form of "n. **Title**: Description"
2254 total, most frequent below:
{'contact information': 102,
  'welcome message': 75,
  'news and events': 72,
  'institutional branding': 64,
  'overview of the faculty': 46,
  'navigation menu': 39,
  'navigation structure': 39,
  'layout and design': 35,
  'language options': 24,
  'title and greeting': 23,
  'navigation and structure': 23,
  'institutional affiliation': 23,
  'introduction to the faculty': 23,
  'institutional information': 22,
  'news and updates': 21,
  'navigation and links': 17,
  'content': 17,
  'navigation': 15,
  'contact information and footer': 14,
  'title and header': 14,
  'news and announcements': 14,
  'university affiliation': 14,
  'university branding': 11,
  'departmental information': 10,
  'faculty-specific content': 10,
  'social media links': 9,
  'layout and structure': 9,
  'departmental structure': 9,
  'language': 8,
  'content focus': 8,
  'study programs': 7,
  'target audience': 7,
  'contact information and social media links': 7,
  'overview of faculty activities': 7,
  'links to sub-pages': 7,
  'faculty name': 7,
  'footer': 6,
  'title and introduction': 6,
  'contact information and links': 6,
  'faculty-specific information': 6,
  'call to action': 6,
  'contact information and location': 6,
  'department name': 6,
  'lack of introductory content': 6,
  'overview of the department': 5,
  'institutional context': 5,
  'content structure': 5,
  'links to related pages': 5,
  'research focus': 5,
  'institutional introduction': 5,
  'news section': 5,
  'scope': 5,
  'copyright information': 5,
}
Then, take some subset of features:
		'lack of introductory content', 
                 'navigation menu', 
                 'contact information', 
                 'university affiliation', 
                 'research focus',
                 'institutional affiliation',
                 'news and updates',
                 'welcome message',
                 'navigation',
                 'group name',
                 'footer content',
                 'specific topic focus'
                 ]
And classify with SUPPORT VECTOR MACHINE the pages based on its features-> if feature is persistent is "rationale" take it as "1", otherwise "0"
0.75/0.25
Classification Report:
              precision    recall  f1-score   support

           0       0.89      0.60      0.72        55
           1       0.71      0.93      0.80        57

    accuracy                           0.77       112
   macro avg       0.80      0.76      0.76       112
weighted avg       0.80      0.77      0.76       112

Accuracy Score: 0.7678571428571429

---------------------------------
NEXT -> consider SENTIMENT Score as additional feature.
Then, for each **Headline** we count sentiment score. And append it to dataset "sentiment_institutes_chairs.json"
AND for each ** Headline** we count sentiment score ONLY for its first sentence and append to dataset -> "sentiment_institutes_chairs_only_first_sentences.json"

FACULTIES ANALYSIS:
-->
all: 2999
true_pos: 149
true_neg: 2215
false_pos: 543
false_neg: 92

precision: 0.2153179190751445
recall: 0.6182572614107884
f1_score: 0.3193997856377277


----------------------------
OPENAI_ANALYSIS_INSTITUTES_CHAIRS
-->
all: 11001
true_pos: 205
true_neg: 9466
false_pos: 448
false_neg: 882

precision: 0.31393568147013784
recall: 0.18859245630174792
f1_score: 0.23563218390804597




----------------------------
LLAMA_ANALYSIS_INSTITUTES_CHAIRS
-->
all: 11001
true_pos: 744
true_neg: 6395
false_pos: 3519
false_neg: 343

precision: 0.17452498240675582
recall: 0.6844526218951242
f1_score: 0.27813084112149533



----------------------------
LLAMA_ANALYSIS_INSTITUTES_CHAIRS_TRAFILATURA_CONTENT
all: 9168
true_pos: 618
true_neg: 6419
false_pos: 1778
false_neg: 353

precision: 0.2579298831385643
recall: 0.6364572605561277
f1_score: 0.36709236709236714


----------------------------
WUPPERTAL INSTITUTES_CHAIRS ONLY:

all: 1820
true_pos: 74
true_neg: 1358
false_pos: 349
false_neg: 39

precision: 0.17494089834515367
recall: 0.6548672566371682
f1_score: 0.27611940298507465

---------------------------------------Moving on to AGGREGATION ALGORITHM---------------------------
Purpose:How good can we find aggregators? Evaluate! The original algorithm taken options(meta, direct, indirect, disambiguate, dynamic) NO LLM!
Input: Single main page url for each university
UDE:

----->Evaluate ude_truth.json and uni_aggregator_prediction_test_ude.json
All: 216
True Positive: 110
False Positive: 83
False Negative: 23
Precision: 0.5699481865284974
Recall: 0.8270676691729323
F1-Score: 0.6748466257668712

----->MUENSTER:
Evaluate muenster_truth.json and uni_aggregator_prediction_test_muenster.json
All: 249
True Positive: 98
False Positive: 118
False Negative: 33
Precision: 0.4537037037037037
Recall: 0.7480916030534351
F1-Score: 0.5648414985590777

----->DORTMUND
Evaluate dortmund_truth.json and uni_aggregator_prediction_test_dortmund.json
All: 158
True Positive: 105
False Positive: 35
False Negative: 18
Precision: 0.75
Recall: 0.8536585365853658
F1-Score: 0.7984790874524715

WUPPERTAL COULDT LOAD PREDICTION JSON.

------------------------------------------------->OLD RESULTS SHOWN IN PAPER<----------------------------------


SPLITTED AGGREGATOR RESULTS:
	Baseline:
    UDE:
        Precision: 0.7294117647058823
        Recall: 0.8266666666666667
        F1-Score: 0.7749999999999999

    Münster:
        Precision: 0.8974358974358975
        Recall: 0.8284023668639053
        F1-Score: 0.8615384615384615

    Dortmund:
        Precision: 0.8157894736842105
        Recall: 0.7654320987654321
        F1-Score: 0.7898089171974522

    Wuppertal:
        Precision: 0.7808219178082192
        Recall: 0.8636363636363636
        F1-Score: 0.8201438848920863



Only disambiguate:

    UDE:
        Precision: 0.7294117647058823
        Recall: 0.8266666666666667
        F1-Score: 0.7749999999999999

    Münster:
        Precision: 0.9032258064516129
        Recall: 0.8284023668639053
        F1-Score: 0.8641975308641976

    Dortmund:
        Precision: 0.8157894736842105
        Recall: 0.7654320987654321
        F1-Score: 0.7898089171974522

    Wuppertal:
        Precision: 0.7808219178082192
        Recall: 0.8636363636363636
        F1-Score: 0.8201438848920863


Only direct:

    UDE:
        Precision: 0.7362637362637363
        Recall: 0.8481012658227848
        F1-Score: 0.788235294117647

    Münster:
        Precision: 0.9058823529411765
        Recall: 0.875
        F1-Score: 0.8901734104046243

    Dortmund:
        Precision: 0.8157894736842105
        Recall: 0.7654320987654321
        F1-Score: 0.7898089171974522

    Wuppertal:
        Precision: 0.7662337662337663
        Recall: 0.8939393939393939
        F1-Score: 0.8251748251748252


Only indirect:

    UDE:
        Precision: 0.7294117647058823
        Recall: 0.8266666666666667
        F1-Score: 0.7749999999999999

    Münster:
        Precision: 0.8974358974358975
        Recall: 0.8284023668639053
        F1-Score: 0.8615384615384615

    Dortmund:
        Precision: 0.8157894736842105
        Recall: 0.7654320987654321
        F1-Score: 0.7898089171974522

    Wuppertal:
        Precision: 0.7808219178082192
        Recall: 0.8636363636363636
        F1-Score: 0.8201438848920863


Only meta:

    UDE:
        Precision: 0.8421052631578947
        Recall: 0.9248554913294798
        F1-Score: 0.8815426997245179

    Münster:
        Precision: 0.8711340206185567
        Recall: 0.8578680203045685
        F1-Score: 0.8644501278772379

    Dortmund:
        Precision: 0.75
        Recall: 0.8536585365853658
        F1-Score: 0.7984790874524715

    Wuppertal:
        Precision: 0.7697841726618705
        Recall: 0.9224137931034483
        F1-Score: 0.8392156862745098


Full:

UDE:
      "Evaluate ude_truth.json and uni_aggregator_prediction_test_ude.json\n",
      "All: 205\n",
      "True Positive: 162\n",
      "False Positive: 31\n",
      "False Negative: 12\n",
      "Precision: 0.8393782383419689\n",
      "Recall: 0.9310344827586207\n",
      "F1-Score: 0.8828337874659401\n",

MUENSTER:
      "Evaluate muenster_truth.json and uni_aggregator_prediction_test_muenster.json\n",
      "All: 237\n",
      "True Positive: 190\n",
      "False Positive: 26\n",
      "False Negative: 21\n",
      "Precision: 0.8796296296296297\n",
      "Recall: 0.9004739336492891\n",
      "F1-Score: 0.8899297423887589\n",

DORTMUND:
      "Evaluate dortmund_truth.json and uni_aggregator_prediction_test_dortmund.json\n",
      "All: 158\n",
      "True Positive: 105\n",
      "False Positive: 35\n",
      "False Negative: 18\n",
      "Precision: 0.75\n",
      "Recall: 0.8536585365853658\n",
      "F1-Score: 0.7984790874524715\n",
WUPPERTAL:
      "Evaluate wuppertal_truth.json and uni_aggregator_prediction_test_wuppertal.json\n",
      "All: 150\n",
      "True Positive: 109\n",
      "False Positive: 34\n",
      "False Negative: 7\n",
      "Precision: 0.7622377622377622\n",
      "Recall: 0.9396551724137931\n",
      "F1-Score: 0.8416988416988418\n",
----->>


F1-SCORES
Setting              | UDE    | Münster | Dortmund | Wuppertal
---------------------|--------|---------|----------|-----------
Baseline             | 0.775  | 0.862   | 0.790    | 0.820      < shown in paper
Only disambiguate    | 0.775  | 0.864   | 0.790    | 0.820
Only direct          | 0.788  | 0.890   | 0.790    | 0.825
Only indirect        | 0.775  | 0.862   | 0.790    | 0.820      < shown in paper
Only meta            | 0.882  | 0.864   | 0.798    | 0.839      < shown in paper
Full                 | 0.882  | 0.889   | 0.7984   | 0.841      < shown in paper





------------------------------------------------------------->LANDING PAGE IDENTIFICATION
Purpose: how good can we define the landing pages right?
Take only the text of the pages from LLM_DATASET and train flan-t5-base, flan-t5-large and distillbert on it. Then predict.

Cross-university -> test on uni but train on 3 other universities

ONLY SINGLE SETTING RESULTS ARE SHOWN IN THE ORGMINER PAPER.
Fine tuned only base models. For llm is "not"

Model                    | University  | Setting                          | Macro F1
-------------------------|-------------|----------------------------------|---------
distilbert-base-uncased  | UDE         | Single (75/25)                   | 0.70
distilbert-base-uncased  | UDE         | Cross-university                 | 0.61
distilbert-base-uncased  | Münster     | Single (75/25)                   | 0.68
distilbert-base-uncased  | Münster     | Cross-university                 | 0.65
distilbert-base-uncased  | Dortmund    | Single (75/25)                   | 0.60
distilbert-base-uncased  | Dortmund    | Cross-university                 | 0.57
distilbert-base-uncased  | Wuppertal   | Single (75/25)                   | 0.62
distilbert-base-uncased  | Wuppertal   | Cross-university                 | 0.55
-------------------------|-------------|----------------------------------|---------
flan-t5-base             | UDE         | Single (75/25)                   | 0.72
flan-t5-base             | UDE         | Cross-university                 | 0.69
flan-t5-base             | Münster     | Single (75/25)                   | 0.79
flan-t5-base             | Münster     | Cross-university                 | 0.68
flan-t5-base             | Dortmund    | Single (75/25)                   | 0.65
flan-t5-base             | Dortmund    | Cross-university                 | 0.65
flan-t5-base             | Wuppertal   | Single (75/25)                   | 0.62
flan-t5-base             | Wuppertal   | Cross-university                 | 0.66
-------------------------|-------------|----------------------------------|---------
flan-t5-large            | UDE         | Single (75/25)                   | 0.79
flan-t5-large            | UDE         | Cross-university                 | 0.65
flan-t5-large            | Münster     | Single (75/25)                   | 0.83
flan-t5-large            | Münster     | Cross-university                 | 0.71
flan-t5-large            | Dortmund    | Single (75/25)                   | 0.72
flan-t5-large            | Dortmund    | Cross-university                 | 0.66
flan-t5-large            | Wuppertal   | Single (75/25)                   | 0.69
flan-t5-large            | Wuppertal   | Cross-university                 | 0.68


------------------------------------------------------->TODO Guideline from previous steps to actual orgminer paper <---------------------------------------
