သိပ်တော့မဟုတ်ပါဘူး။ အင်တာနက်ထဲက Corpus of Pyu Inscriptions ဆိုတဲ့ဝဘ်စာမျက်နှာ (http://hisoma.huma-num.fr/exist/apps/pyu/index2.html) ပေါ်မှာပျူကမ္ပည်းစာတခုချင်းပြထားတယ်။ ဒါကိုကိုယ့်ကွန်ပျူတာထဲကိုတပေါင်းထဲရောက်လာအောင်စမ်းကြည့်တာပါ။
အဲဒီမှာ ပျူကမ္ပည်းစာဓါတ်ပုံ၊အင်္ဂလိပ်စာလုံးနဲ့အက္ခရာဖလှယ်ထားချက်၊ ဘာသာပြန်ချက်၊ တည်နေရာနဲ့နောက်ခံအချက်လက် စတာတွေကို ကမ္ပည်းစာတခုချင်းစီပဲဖတ်နိုင်တယ်။ အဲဒါကို ရေးသွင်းချက် ၁၆၁-ခုလုံးအတွက်ဒေါင်းလုတ်ဆွဲဖို့လဲပေးမထားပါဘူး။ သူ့စာတွေကို XML စနစ်နဲ့ရေးပြီးသိမ်းထားတာပါ။ အင်တာနက်ပေါ်ကအချက်လှောင်တဲ့ဝဘ်စာမျက်တွေဟာလူထုကိုမျှဝေဘို့ API ဆိုတဲ့အချက်အလက်ဆက်သွယ်ရယူနိုင်တဲ့နည်းလမ်းကိုဖန်တည်းပေးထားတတ်ပါတယ်။ ဒီနည်းကိုသုံးပြီးကိုယ်လိုချင်တဲ့အချက်အလက်တွေကို သက်တောင့်သက်သာနဲ့ရယူနိုင်ပါတယ်။
ပျူစာစုဝဘ်စာမျက်နှာမှာ API ကိုမတွေ့လို့သေချာအောင် AI ကိုမေးကြည့်တော့ မရှိတာသေချာသွားတယ်။ သူက ပညာရပ်မှတ်တမ်းတွေစုတဲ့ဝဘ်စာမျက်နှာတွေမှာရှာကြည့်ဘို့နဲ့ နောက်တနည်းက web scraping လို့ခေါ်တဲ့ ဝဘ်စာမျက်ပေါ်ကလိုချင်တာထုတ်(ခြစ်) ယူတဲ့နည်းသုံးဘို့အကြံပေးတယ်။ ကျနော့အဖို့ ပထမနည်းရော ဒုတိယနည်းနဲ့ပါမစိမ်းပါဘူး။ ၂၀၂၀-မှာစမ်းသပ်ခဲ့ဘူးတယ်။
ကျနော့ရဲ့ခုစမ်းသပ်မှုဟာပြောခဲ့တဲ့ပျူစာစုထဲကအချက်အလက်တွေကို R-ကွန်ပျူတာဘာသာစကားသုံးပြီးစုစည်းကြည့်တာဖြစ်ပါတယ်။ ဒီအတွက် “Grok”၊ “deepSeek” နဲ့ “chatGPT” တို့ဆီကအကြံဉာဏ်တွေယူပြီး ရောသမမွှေထားလို့အောင်မြင်ပါတယ်။ ပရိုဂရမ်ရဲ့ကျောရိုးအတွက် deepSeek ရေးပြတဲ့နမူနာကို အဓိကမှီးပါတယ်။
ကံကောင်းတာက AI တခုညွှန်ပြလို့ ပြောခဲ့တဲ့ပျူစာစုထဲက ပျူကမ္ပည်းစာအားလုံးကိုစုစည်းထားတဲ့ “Corpus of Pyu inscriptions 180326.zip” ဖိုင် ကို Zenodo ဝဘ်စာမျက်နှာ (https://zenodo.org/records/1207290) မှာတွေ့ပြီး ဆွဲယူသုံးနိုင်တာဖြစ်ပါတယ်။
အချောသပ်ပရိုဂရမ်ကဒီလိုပါ -
library(xml2)
library(purrr)
library(dplyr)
# Download zip file and extract xml files
url <- "https://zenodo.org/records/1207290/files/Corpus%20of%20Pyu%20inscriptions%20180326.zip?download=1"
temp_zip <- tempfile(fileext = ".zip")
download.file(url, temp_zip, mode = "wb")
zip_dir <- tempfile()
dir.create("zip180326_dir")
unzip(temp_zip, exdir = "zip180326_dir")
PYUxml_files <- list.files("zip180326_dir", pattern = "\\.xml$", full.names = TRUE, recursive = FALSE)
# TEI namespace definition
tei_ns <- c(tei = "http://www.tei-c.org/ns/1.0")
# Enhanced extraction function with dynamic namespace handling
safe_extract <- function(doc, xpath, attr = NULL, ns = xml_ns(doc)) {
node <- xml_find_first(doc, xpath, ns)
# mtnn, March 12, 2025
# if (length(node) == 0 || is.na(node)) return(NA_character_)
if (length(node) == 0 || is.na(node)) return(NA_character_) else node <- xml_find_all(doc, xpath, ns)
if (!is.null(attr)) xml_attr(node, attr) else xml_text(node) %>% paste0(collapse = " ")
}
# Extract complete text for dimensions, mtnn, March 11, 2025
supp <- function(doc){
dO <- xml_find_all(doc, "//d1:support/d1:p/d1:objectType") %>% xml_text()
dM <- xml_find_all(doc, "//d1:support/d1:p/d1:material") %>% xml_text()
# Get the dimensions right
dims <- xml_find_all(doc, "//d1:support/d1:p/d1:dimensions")
# Process each dims
result <- sapply(dims, function(d) {
#dName <- xml_name(xml_child(xml_find_first(d, "//d1:dimensions")))
dName <- xml_name(xml_children(xml_find_first(d, "//d1:dimensions")))
dV <- xml_children(xml_find_first(d, "//d1:dimensions")) %>% xml_text()
dU <- xml_attr(xml_find_first(doc, ".//d1:dimensions"), "unit")
unlist(paste(dName, dV, dU, collapse = ", "))
})
paste0(dO, "; ", dM, " ", result, ".")
}
# Modified parser with dynamic TEI prefix handling
parse_epidoc <- function(file_path) {
doc <- read_xml(file_path)
ns <- xml_ns(doc)
# Find TEI namespace prefix dynamically
tei_uri <- "http://www.tei-c.org/ns/1.0"
tei_prefix <- names(ns)[ns == tei_uri]
if (length(tei_prefix) == 0) {
warning("No TEI namespace found in ", file_path)
return(NULL)
}
tei_prefix <- tei_prefix[1]
# Create namespace-aware XPath builder
tei <- function(element) paste0(tei_prefix, ":", element)
# Metadata extraction (FIXED SYNTAX)
metadata <- list(
title = safe_extract(doc, paste0("//", tei("titleStmt"), "/", tei("title")), ns = ns),
Support = supp(doc),
Text = safe_extract(doc, paste0("//", tei("textLang")), ns = ns),
Date = safe_extract(doc, paste0("//", tei("origDate")), ns = ns),
Origin = safe_extract(doc, paste0("//", tei("origPlace")), ns = ns),
Provenance = safe_extract(doc, paste0("//", tei("provenance")), ns = ns),
Visual_Documentation = safe_extract(doc, paste0("//", tei("listBibl")), ns = ns),
Editors = safe_extract(doc, paste0("//", tei("editor")), ns = ns) %>% gsub(" ", ", ", .),
Publication_history = safe_extract(doc, paste0("//", tei("div[@type='bibliography']"), "/", tei("p")), ns = ns)
)
# Text content extraction
content <- list(
Edition = safe_extract(doc, paste0("//", tei("div[@type='edition']")), ns = ns),
Apparatus = safe_extract(doc, paste0("//", tei("div[@type='apparatus']")), ns = ns),
# inscription = safe_extract(doc, paste0("//", tei("div[@type='edition']"), "/", tei("ab")), ns = ns),
Translation = safe_extract(doc, paste0("//", tei("div[@type='translation']"), "/", tei("ab")), ns = ns),
Commentary = safe_extract(doc, paste0("//", tei("div[@type='commentary']")), ns = ns)
)
# Combine all data
c(metadata, content, list(file_path = basename(file_path)))
}
# Process files with improved error handling
results <- map_dfr(PYUxml_files, ~{
tryCatch({
res <- parse_epidoc(.x)
if (!is.null(res)) {
as_tibble(res) %>%
mutate(across(everything(), as.character))
}
}, error = function(e) {
message("Error processing ", .x, ": ", e$message)
NULL
})
})
# View results
glimpse(results)
# Write results to text file
write.csv(results, "pyuCorpus_18326.csv")
ဒီပရိုဂရမ်ကိုမောင်းကြည့်လိုက်တော့ လိုချင်တဲ့အတိုင်း အချက်အလက်တွေပါတဲ့ dataframe ကိုထုတ်ပေးတယ်။ ဒါပေမဲ့ xml ဖိုင် ၄-ခုကပြဿနာတက်တယ်။
chatGPT ကိုမေးတော့ ၄-ဖိုင်ပြဿနာရှင်းဘို့ Python ပရိုဂရမ် (script) လေးရေးပေးတယ်။ သူ့ကိုသုံးလိုက်တော့ PYU048.xml ဖိုင်ကလွဲရင်ကျန်တာပြေလည်သွားတယ်။ R ကွန်ပျူတာဘာသာစကားနဲ့အလုပ်လုပ်နေတုန်းမှာ Python script ကိုကြားညှပ်သုံးလို့ရနိုင်တာကြောင့် Python script ကိုဒီလိုမောင်းတယ် -
import os
import shutil
import unicodedata
from lxml import etree
# Folder containing XML files (change this to your actual folder)
XML_FOLDER = "toRepair_XML"
# Backup folder for original files
BACKUP_FOLDER = os.path.join(XML_FOLDER, "backup")
os.makedirs(BACKUP_FOLDER, exist_ok=True)
# Function to clean invalid Unicode characters
def clean_text(text):
# Normalize and remove invalid surrogate characters
return "".join(c for c in text if unicodedata.category(c) != "Cs")
def fix_xml(file_path):
try:
# Backup original file
backup_path = os.path.join(BACKUP_FOLDER, os.path.basename(file_path))
shutil.copy2(file_path, backup_path)
# Read file contents
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
content = f.read().strip() # Strip whitespace to check if empty
# Skip empty or corrupt files
if not content or not content.startswith("<"):
print(f"⚠️ Skipping (Empty or Corrupt): {file_path}")
return
# Clean text from invalid characters
cleaned_content = clean_text(content)
# Parse XML with error recovery
parser = etree.XMLParser(recover=True)
tree = etree.fromstring(cleaned_content.encode("utf-8"), parser)
# Ensure proper XML declaration before saving
fixed_path = file_path
with open(fixed_path, "wb") as f:
f.write(b'<?xml version="1.0" encoding="UTF-8"?>\n') # Force correct encoding
f.write(etree.tostring(tree, pretty_print=True, encoding="utf-8"))
print(f"✅ Fixed: {file_path}")
except Exception as e:
print(f"❌ Error in {file_path}: {e}")
# Get all XML files in the folder
xml_files = [f for f in os.listdir(XML_FOLDER) if f.endswith(".xml")]
# Process each XML file
for xml_file in xml_files:
file_path = os.path.join(XML_FOLDER, xml_file)
fix_xml(file_path)
print("\n🎉 XML repair completed! Check the 'backup' folder for originals.")
အဖြေကဒီလိုထွက်တယ် -
ပြင်ဘို့ကျန်တဲ့ PYU048.xml ကို NotePad နဲ့ဖတ်ကြည့်တော့ ဒုတိယစာကြောင်းရဲ့အစမှာ tag သာရှိရမဲ့အစား “oo” ပါနေတယ်။
ဒါကြောင့် “oo” ကိုဖျက်လိုက်တော့ပြေလည်သွားတယ်။ ပြင်ထားတဲ့ ၄-ဖိုင်ကိုအစားထိုးပြီးအပေါ်မှာပြခဲ့တဲ့ပင်မပရိုဂရမ်ကိုမောင်းတော့အဆင်ပြေသွားတယ်။ ထွက်လာတဲ့ dataframe ရဲ့တစိပ်တပိုင်းနမူနာက ဒီလိုပါ -
Dataframe မှာစုစည်းထားတဲ့ ပျူကမ္ပည်းစာအချက်အလက်တွေကို မျှဝေဘို့ “pyuCorpus_18326.csv” ဖိုင်အဖြစ်ရေးထုတ်ပါတယ်။ စိတ်ဝင်စားရင် ဒီမှာ ယူနိုင်ပါတယ်။
မှတ်ချက်။ ။(၁) ဒီရေးတင်ချက်ပါအချက်အလက်များနဲ့ မျှဝေထားတဲ့ဖိုင်ပါအချက်အလက်များမှာ အမှားပါရှိနိုင်ပါတယ်။ (၂) ခုထုတ်ယူထားတဲ့အချက်အလက်များဟာ Zenodo ဝဘ်စာမျက်နှာပေါ်က ၂၀၁၈-ခု၊မတ်လ ၂၆-ရက်နေ့စွဲပါ Corpus of Pyu inscriptions 180326.zip ဖိုင်ကဖြစ်ပါတယ်။ မူရင်းပျူစာစုပြုစုသူများက စဉ်ဆက်မပြတ်ပြုပြင်မှုတွေလုပ်တယ်လို့သိရပါတယ်။ (၃) ယခုလုပ်ဆောင်မှုမှာ အမှားပါရှိနေတဲ့ဖိုင်၄ဖိုင်ကိုပြင်ပြီးသုံးခဲ့ပါတယ်။ လိုချင်မှလိုမယ်။ ဒါဟာ မူရင်း ပျူစာစုပြုစုသူများကတမင်အမှတ်အသားလုပ်ပြီးချန်ခဲ့တာလဲ ဖြစ်နိုင်ပါတယ်။ (၄) မျှဝေထားတဲ့ pyuCorpus_18326.csv ဖိုင်ကို Notepad နဲ့ဖတ်နိုင်တယ်။ Microsoft Office သို့မဟုတ်တခြား Office software (ဥပမာ Libre Office) နဲ့ဖတ်ပြီး Spreadsheet အဖြစ်နဲ့လဲ save လုပ်နိုင်ပါတယ်။
The shared csv file is revised by adding an "id" column as it was found that "id" does not always correspond to the "file_path".
ReplyDelete