Transformers
Italian
English
semantic-search
explainable-ai
faiss
ai-ethics
responsible-ai
llm
prompt-engineering
multimodal-ai
ai-transparency
ethical-intelligence
explainable-llm
cognitive-ai
ethical-ai
scientific-retrieval
modular-ai
memory-augmented-llm
trustworthy-ai
reasoning-engine
ai-alignment
next-gen-llm
thinking-machines
open-source-ai
explainability
ai-research
semantic audit
cognitive agent
human-centered-ai
Create hypothesis_validation.py
Browse files
src/evaluation/hypothesis_validation.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# © 2025 Elena Marziali — Code released under Apache 2.0 license.
|
| 2 |
+
# See LICENSE in the repository for details.
|
| 3 |
+
# Removal of this copyright is prohibited.
|
| 4 |
+
|
| 5 |
+
# Generate an automatic report
|
| 6 |
+
def generate_markdown_report(
|
| 7 |
+
title="Automatic Report",
|
| 8 |
+
description="Automatically generated scientific summary.",
|
| 9 |
+
articles=None,
|
| 10 |
+
images=None,
|
| 11 |
+
captions=None,
|
| 12 |
+
filename="report.md"
|
| 13 |
+
):
|
| 14 |
+
"""
|
| 15 |
+
Generates a Markdown file with:
|
| 16 |
+
- Title and description
|
| 17 |
+
- Scientific articles with abstract and link
|
| 18 |
+
- Images and associated captions (if available)
|
| 19 |
+
|
| 20 |
+
All arguments are optional. A coherent structure is created regardless.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
# Safe fallback for each parameter
|
| 24 |
+
articles = articles if isinstance(articles, list) else []
|
| 25 |
+
images = images if isinstance(images, list) else []
|
| 26 |
+
captions = captions if isinstance(captions, list) else []
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
with open(filename, "w", encoding="utf-8") as f:
|
| 30 |
+
f.write(f"# {title}\n\n")
|
| 31 |
+
f.write(f"{description}\n\n")
|
| 32 |
+
|
| 33 |
+
f.write("## Scientific Articles\n\n")
|
| 34 |
+
if articles:
|
| 35 |
+
for i, art in enumerate(articles[:5]):
|
| 36 |
+
article_title = art.get("titolo", f"Article {i+1}")
|
| 37 |
+
abstract = art.get("abstract", "Abstract not available.")
|
| 38 |
+
url = art.get("url", "#")
|
| 39 |
+
f.write(f"**{i+1}. {article_title}**\n")
|
| 40 |
+
f.write(f"{abstract}\n\n[Link to article]({url})\n\n")
|
| 41 |
+
else:
|
| 42 |
+
f.write("No articles available.\n\n")
|
| 43 |
+
|
| 44 |
+
if images:
|
| 45 |
+
f.write("## Figures\n\n")
|
| 46 |
+
for i, img_path in enumerate(images):
|
| 47 |
+
caption = captions[i] if i < len(captions) else f"Figure {i+1}"
|
| 48 |
+
f.write(f"\n\n*{caption}*\n\n")
|
| 49 |
+
|
| 50 |
+
print(f"Markdown report successfully generated: {filename}")
|
| 51 |
+
except Exception as e:
|
| 52 |
+
print(f"Error during report generation: {e}")
|
| 53 |
+
|
| 54 |
+
# === Markdown report generation ===
|
| 55 |
+
def generate_markdown_report(title, description, articles, filename="report.md"):
|
| 56 |
+
if not isinstance(articles, list):
|
| 57 |
+
logging.error(f"[generate_markdown_report] 'articles' is not a valid list: {type(articles)}")
|
| 58 |
+
print("Error: unable to generate report. Invalid article format.")
|
| 59 |
+
return
|
| 60 |
+
|
| 61 |
+
with open(filename, "w", encoding="utf-8") as f:
|
| 62 |
+
f.write(f"# {title}\n\n{description}\n\n## Scientific Articles\n\n")
|
| 63 |
+
for i, art in enumerate(articles[:5]):
|
| 64 |
+
if isinstance(art, dict) and all(k in art for k in ["titolo", "abstract", "url"]):
|
| 65 |
+
f.write(f"**{i+1}. {art['titolo']}**\n{art['abstract']} ([Link]({art['url']}))\n\n")
|
| 66 |
+
else:
|
| 67 |
+
f.write(f"**{i+1}. Article data not available or incomplete.**\n\n")
|
| 68 |
+
print(f"Markdown report generated: {filename}")
|