read these files one is dessertation from which the article is extracted kindly change references and in text citation references and in text reference number should be parallel bcz in article discussion section reference no 74 and onward present but in refertnce section only 25 references present so change the number and maintain and align with each other but dont change anythig else everything should be same in article
cd /home/daytona/workspace && mkdir -p reference-fix && pandoc "/home/daytona/workspace/attachments/73a9d27d-4bce-4204-91aa-3c981b20c922/Prof-10503.docx" -o reference-fix/article.md 2>&1 && echo "DONE"
python3 -c " import pdfplumber pdf_path = '/home/daytona/workspace/attachments/73a9d27d-4bce-4204-91aa-3c981b20c922/170862711348241-synopsis-document_1.pdf' with pdfplumber.open(pdf_path) as pdf: print(f'Total pages: {len(pdf.pages)}') # Print last few pages (likely references) for i, page in enumerate(pdf.pages): text = page.extract_text() if text and ('74' in text or '75' in text or '76' in text or '77' in text or '78' in text or 'Erbil' in text or 'Rosato' in text or 'Thomusch' in text or 'Smith' in text or 'Zhang' in text): print(f'--- PAGE {i+1} ---') print(text[:3000]) print() "
python3 -c " from pypdf import PdfReader pdf_path = '/home/daytona/workspace/attachments/73a9d27d-4bce-4204-91aa-3c981b20c922/170862711348241-synopsis-document_1.pdf' reader = PdfReader(pdf_path) print(f'Total pages: {len(reader.pages)}') # Read last 10 pages for i in range(max(0, len(reader.pages)-10), len(reader.pages)): text = reader.pages[i].extract_text() if text: print(f'--- PAGE {i+1} ---') print(text[:2000]) " 2>&1 | head -200
python3 << 'EOF' from pypdf import PdfReader pdf_path = '/home/daytona/workspace/attachments/73a9d27d-4bce-4204-91aa-3c981b20c922/170862711348241-synopsis-document_1.pdf' reader = PdfReader(pdf_path) print(f'Total pages: {len(reader.pages)}') # Search all pages for reference 74 or author names for i in range(len(reader.pages)): text = reader.pages[i].extract_text() or '' if any(name in text for name in ['Erbil', 'Rosato', 'Thomusch', 'Smith', 'Zhang', 'ref 74', '74.', '75.', '76.', '77.', '78.']): print(f'--- PAGE {i+1} ---') print(text[:3000]) print() EOF
python3 << 'EOF' from pypdf import PdfReader pdf_path = '/home/daytona/workspace/attachments/73a9d27d-4bce-4204-91aa-3c981b20c922/170862711348241-synopsis-document_1.pdf' reader = PdfReader(pdf_path) # Print all pages text to find references for i in range(len(reader.pages)): text = reader.pages[i].extract_text() or '' if text.strip(): print(f'--- PAGE {i+1} ---') print(text[:500]) print() EOF
python3 << 'EOF' # Read the full markdown to get all references with open('/home/daytona/workspace/reference-fix/article.md', 'r') as f: content = f.read() # Find the REFERENCES section ref_idx = content.find('**REFERENCES**') print(content[ref_idx:]) EOF
python3 << 'EOF' import shutil, zipfile, os, re src = '/home/daytona/workspace/attachments/73a9d27d-4bce-4204-91aa-3c981b20c922/Prof-10503.docx' dst = '/home/daytona/workspace/reference-fix/Prof-10503-fixed.docx' # Copy original shutil.copy2(src, dst) # Unpack unpack_dir = '/home/daytona/workspace/reference-fix/unpacked' os.makedirs(unpack_dir, exist_ok=True) with zipfile.ZipFile(dst, 'r') as z: z.extractall(unpack_dir) # Read document.xml doc_xml_path = os.path.join(unpack_dir, 'word', 'document.xml') with open(doc_xml_path, 'r', encoding='utf-8') as f: xml = f.read() print("File read, length:", len(xml)) # Search for superscript references 74, 75, 76, 77, 78 # In docx, superscripts are in <w:vertAlign w:val="superscript"/> # Let's find occurrences of 74, 75, 76, 77, 78 in the text import re # Find all text nodes containing these numbers pattern = r'<w:t[^>]*>([^<]*)</w:t>' matches = [(m.start(), m.group(0), m.group(1)) for m in re.finditer(pattern, xml)] # Print context around 74, 75, 76, 77, 78 for pos, full, text in matches: if text.strip() in ['74', '75', '76', '77', '78']: # Print surrounding 500 chars print(f"\n=== Found '{text}' at pos {pos} ===") print(xml[max(0,pos-300):pos+300]) print() EOF
python3 << 'PYEOF' import shutil, zipfile, os, re src = '/home/daytona/workspace/attachments/73a9d27d-4bce-4204-91aa-3c981b20c922/Prof-10503.docx' dst = '/home/daytona/workspace/reference-fix/Prof-10503-fixed.docx' # Copy using open/read/write with open(src, 'rb') as f: data = f.read() with open(dst, 'wb') as f: f.write(data) # Unpack unpack_dir = '/home/daytona/workspace/reference-fix/unpacked' if os.path.exists(unpack_dir): shutil.rmtree(unpack_dir) os.makedirs(unpack_dir, exist_ok=True) with zipfile.ZipFile(dst, 'r') as z: z.extractall(unpack_dir) # Read document.xml doc_xml_path = os.path.join(unpack_dir, 'word', 'document.xml') with open(doc_xml_path, 'r', encoding='utf-8') as f: xml = f.read() print("File read, length:", len(xml)) # Find text nodes with 74,75,76,77,78 pattern = r'<w:t[^>]*>([^<]*)</w:t>' matches = [(m.start(), m.group(0), m.group(1)) for m in re.finditer(pattern, xml)] for pos, full, text in matches: if text.strip() in ['74', '75', '76', '77', '78']: print(f"\n=== Found '{text}' at pos {pos} ===") print(repr(xml[max(0,pos-400):pos+400])) print() PYEOF
python3 << 'PYEOF' import zipfile, os, re, shutil unpack_dir = '/home/daytona/workspace/reference-fix/unpacked' doc_xml_path = os.path.join(unpack_dir, 'word', 'document.xml') with open(doc_xml_path, 'r', encoding='utf-8') as f: xml = f.read() # The superscript references 74,75,76,77,78 need to become 26,27,28,29,30 # We need to replace them ONLY when they appear as superscript text nodes # Pattern: <w:vertAlign w:val="superscript"/></w:rPr><w:t>NUMBER</w:t> # Map old -> new mapping = { '74': '22', '75': '23', '76': '24', '77': '25', '78': '26', } # The superscript pattern is: # <w:vertAlign w:val="superscript"/></w:rPr><w:t>74</w:t> # Replace each one specifically for old, new in mapping.items(): pattern = r'(<w:vertAlign w:val="superscript"/></w:rPr><w:t>)' + re.escape(old) + r'(</w:t>)' replacement = r'\g<1>' + new + r'\g<2>' new_xml = re.sub(pattern, replacement, xml) count = len(re.findall(pattern, xml)) print(f"Replacing superscript {old} -> {new}: {count} occurrences") xml = new_xml # Now find where the reference list ends (after ref 25) and add new refs # Find the last reference "25\." in the document # Refs are plain text paragraphs ending with ". Dohán O..." # We need to find the paragraph containing "25." and add after it # Let's find the last paragraph of ref 25 ref25_search = 'Endocr Rev. 2003 Feb. 24(1):48-77.' pos25 = xml.find(ref25_search) print(f"\nFound ref 25 ending at pos: {pos25}") # Find the end of that paragraph (</w:p>) para_end_pos = xml.find('</w:p>', pos25) print(f"Paragraph end pos: {para_end_pos}") # Now we need to add 5 new reference paragraphs after this # We need to copy the XML structure of an existing reference paragraph # Let's find the paragraph containing ref 25's text to copy its style # Find start of paragraph containing ref 25 para_start = xml.rfind('<w:p ', 0, pos25) ref25_para = xml[para_start:para_end_pos+6] # +6 for </w:p> print(f"\nRef 25 paragraph (first 500 chars):\n{ref25_para[:500]}") PYEOF