Finally I solved the problem, but not with ChatGPT or Claude. No other AI could find the solution, because it didn’t know how to think about the solution.
In fact, to find the solution to this problem, you had to assign some identifiers to each tag, and do multiple searches.
ChatGPT or Claude, or other AIs, will have to seriously consider this type of solution for such problems.
Here are the specifications, the way I thought about solving the problem. It’s a different way of thinking about doing PARSINGS.
https://pastebin.com/as2yw1UQ
Python code made by a friend of mine. I think the solution, he made the code:
from bs4 import BeautifulSoup
import re
def count_words(text):
"""Numără cuvintele dintr-un text."""
return len(text.strip().split())
def get_greek_identifier(word_count):
"""Determină identificatorul grecesc bazat pe numărul de cuvinte."""
if word_count < 7:
return 'α'
elif word_count <= 14:
return 'β'
else:
return 'γ'
def get_tag_type(tag):
"""Determină tipul tagului (A, B, sau C)."""
if tag.find('span'):
return 'A'
elif 'text_obisnuit2' in tag.get('class', []):
return 'B'
return 'C'
def analyze_tags(content):
"""Analizează tagurile și returnează informații despre fiecare tag."""
soup = BeautifulSoup(content, 'html.parser')
tags_info = []
article_content = re.search(r'<!-- ARTICOL START -->(.*?)<!-- ARTICOL FINAL -->',
content, re.DOTALL)
if article_content:
content = article_content.group(1)
soup = BeautifulSoup(content, 'html.parser')
for i, tag in enumerate(soup.find_all('p', recursive=False)):
text_content = tag.get_text(strip=True)
tag_type = get_tag_type(tag)
word_count = count_words(text_content)
greek_id = get_greek_identifier(word_count)
tags_info.append({
'number': i + 1,
'type': tag_type,
'greek': greek_id,
'content': str(tag),
'text': text_content
})
return tags_info
def compare_tags(ro_tags, en_tags):
"""Compară tagurile și găsește diferențele."""
wrong_tags = []
i = 0
j = 0
while i < len(ro_tags):
ro_tag = ro_tags[i]
if j >= len(en_tags):
wrong_tags.append(ro_tag)
i += 1
continue
en_tag = en_tags[j]
if ro_tag['type'] != en_tag['type']:
wrong_tags.append(ro_tag)
i += 1
continue
i += 1
j += 1
return wrong_tags
def format_results(wrong_tags):
"""Formatează rezultatele pentru afișare și salvare."""
type_counts = {'A': 0, 'B': 0, 'C': 0}
type_content = {'A': [], 'B': [], 'C': []}
for tag in wrong_tags:
type_counts[tag['type']] += 1
type_content[tag['type']].append(tag['content'])
# Creăm rezultatul formatat
result = []
# Prima linie cu sumarul
summary_parts = []
for tag_type in ['A', 'B', 'C']:
if type_counts[tag_type] > 0:
summary_parts.append(f"{type_counts[tag_type]} taguri de tipul ({tag_type})")
result.append("In RO exista in plus fata de EN urmatoarele: " + " si ".join(summary_parts))
# Detaliile pentru fiecare tip de tag
for tag_type in ['A', 'B', 'C']:
if type_counts[tag_type] > 0:
result.append(f"\n{type_counts[tag_type]}({tag_type}) adica asta {'taguri' if type_counts[tag_type] > 1 else 'tag'}:")
for content in type_content[tag_type]:
result.append(content)
result.append("") # Linie goală pentru separare
return "\n".join(result)
def merge_content(ro_tags, en_tags, wrong_tags):
"""Combină conținutul RO și EN, inserând tagurile wrong în pozițiile lor originale."""
merged_tags = []
# Creăm un dicționar pentru tagurile wrong indexat după numărul lor original
wrong_dict = {tag['number']: tag for tag in wrong_tags}
# Parcurgem pozițiile și decidem ce tag să punem în fiecare poziție
current_en_idx = 0
for i in range(max(len(ro_tags), len(en_tags))):
position = i + 1
# Verificăm dacă această poziție este pentru un tag wrong
if position in wrong_dict:
merged_tags.append(wrong_dict[position]['content'])
elif current_en_idx < len(en_tags):
merged_tags.append(en_tags[current_en_idx]['content'])
current_en_idx += 1
return merged_tags
def save_results(merged_content, results, output_path):
"""Salvează conținutul combinat și rezultatele în fișierul de output."""
final_content = '<!-- REZULTATE ANALIZA -->\n'
final_content += '<!-- ARTICOL START -->\n'
# Adaugă conținutul combinat
for tag in merged_content:
final_content += tag + '\n'
final_content += '<!-- ARTICOL FINAL -->\n'
final_content += '<!-- FINAL REZULTATE ANALIZA -->\n'
# Adaugă rezultatele analizei
final_content += results
# Salvează în fișier
with open(output_path, 'w', encoding='utf-8') as file:
file.write(final_content)
# Citește fișierele
with open(r'd:/3/ro/incotro-vezi-tu-privire.html', 'r', encoding='utf-8') as file:
ro_content = file.read()
with open(r'd:/3/en/where-do-you-see-look.html', 'r', encoding='utf-8') as file:
en_content = file.read()
# Definește calea pentru fișierul de output
output_path = r'd:/3/Output/where-do-you-see-look.html'
# Analizează tagurile
ro_tags = analyze_tags(ro_content)
en_tags = analyze_tags(en_content)
# Găsește diferențele
wrong_tags = compare_tags(ro_tags, en_tags)
# Formatează rezultatele
results = format_results(wrong_tags)
# Generează conținutul combinat
merged_content = merge_content(ro_tags, en_tags, wrong_tags)
# Afișează rezultatele în consolă
print(results)
# Salvează rezultatele în fișierul de output
save_results(merged_content, results, output_path)