تحديد لغة صفحة HTML

أرسل من قبل hanisaf في السبت, 2007/09/08 - 5:08am.
عضو فعال

تاريخ التسجيل: 2004-03-18
مشاركات: 313

الجامعة: غير ذلك
الكلية: الهندسة المعلوماتية
المرحلة: ماجستير
الاختصاص: ذكاء صنعي

أريد معرفة ما إذا كانت صفحة معينة مكتوبة بالعربي.
طبعاً لتحديد هذا بشكل دقيق يجب تحليل محتوى الصفحة بشكل كامل, غير أن هذا يستهلك كثيرا من الوقت خاصة إذا كان عدد الصفحات المطلوب تحليلها كبير.
أنا أبحث عن طريقة تقريبية لتحديد اللغة من خلال معاينة الURL أو الHEADERS .
على سبيل المثال إذا كانت الصفحة من نطاق عربي فهي على الأغلب مكتوبة بالعربية.
المشكلة أن معظم الصفحات العربية غير متواجدة على نطاقات عربية, لذا فكرت بمعاينة الcharset في ال headers
وجدت أن كثيرا من الصفحات العربية مكتوبة باستخدام windows-1256, وهذا شيء جيد لكنه غير كاف, حيث أن بعض الصفحات تستخدم ال utf-8
سؤالي بالتحديد: إذا كانت الصفحة مكتوبة بالutf-8 هل هنالك من علامة تدل على اللغة المستخدم؟ وهل توجد علامات أخرى ممكن استخدامها لتحديد اللغة بغض النظر عن ال charset ؟

 
دخول أو تسجيل لإرسال التعليقات | قراءة: 429

خيارات عرض التعليقات

اختر طريقتك المفضلة لعرض التعليقات و اضغط "حفظ الإعدادات" لتفعيل تغييراتك.
الأحد, 2007/09/09 - 12:53am
عضو فعال

تاريخ التسجيل: 2004-03-18
مشاركات: 313

الجامعة: غير ذلك
الكلية: الهندسة المعلوماتية
المرحلة: ماجستير
الاختصاص: ذكاء صنعي

?

 
دخول أو تسجيل لإرسال التعليقات
الأحد, 2007/09/09 - 12:56am
عضو فعال
صورة iman

تاريخ التسجيل: 2006-12-01
مشاركات: 275

طيب ممكن توضح السؤال اكتر شو الهدف من انك تعرف شو لغة صفحة ال html ?

صفحة ال html فيك تحط فيها شو ما بدك واكتر من لغه بقى شو مأصدك ؟

How Perfect You are O Allah, and I praise You. LA Ilah Ila Lah, I seek Your forgiveness and turn to You in repentance

 
دخول أو تسجيل لإرسال التعليقات
الأحد, 2007/09/09 - 1:52am
عضو فعال

تاريخ التسجيل: 2004-03-18
مشاركات: 313

الجامعة: غير ذلك
الكلية: الهندسة المعلوماتية
المرحلة: ماجستير
الاختصاص: ذكاء صنعي

الهدف هو تنزيل أكبر عدد ممكن من الصفحات المكتوبة باللغة العربية لإجراء دراسات إحصائية عليها والاستفادة منها في عدة مشاريع.

 
دخول أو تسجيل لإرسال التعليقات
الأحد, 2007/09/09 - 10:44am
صورة as_els

تاريخ التسجيل: 2005-02-20
مشاركات: 248

الجامعة: دمشق
المرحلة: متخرج
الاختصاص: هندسة شبكات

Hey,
sorry for being late,
a 3 months before I put the same question here with no luck with answers,
later I solved the problem as follows (this is the same way u r thinking in)
1- first check if the domain name is arabic domain witch are
( .ps .sy .bh .dz .eg .iq .jo .kw .lb .ly .ma .om .qa .sa .sd .so .ae .tn .ye .mr)
if not check if the site contains a language tag indecator
2- second check the meta tag charset
if arabic encoding then
arabic
else
if UTF-8
do some process here *
else
not arabic

* the hall idea of this is the UTF-8 process algorithm
as u know every charachter in utf-8 has a uniqe representation (Unicode), so u can get the most repeated arabic charachters like (alef , lam for example) and make a quick search for it in the page content

This algorithm works fine on about 95% of arabic sites I tried on
I'll put the function here to make u see the process



function check_url_status($url)
{
    $results_array=array();    
    $ok=check_if_exists($url);
    if($ok==1)
    {
        $results_array[0]="Y";//Url exists</p>

<p>        /*  get the  ip address of the site */
        $http_pos=0;
        $domain_pos=0;
        $site=$url;
        $http_pos=strpos($site,'http://',0);
        if($http_pos!==false)
            $domain_pos=$http_pos+7;
        $parsed_site=substr($site,$domain_pos);
        $ip = gethostbyname($parsed_site);
        $results_array[2]=$ip;
        /* get the country of the site */
        $country = get_country_from_ip($ip);
        $results_array[3]=$country;
        /* Check site language*/
        $site=$url;
        /* check if arabic tag found in the site */
        $lang_flag1=$this->search_page($site,'lang=ar');
        $text=$this->text_to_search;
        $text = strtolower($text);
        $lang_flag2=$this->search_text($text,'lang="ar"');
        $lang_flag3=$this->search_text($text,"lang='ar'");
        /*       
            the code to check if the lang=ar is in a tag and not in the body of the page goes here
        */
        /* get the encoding */
        $encoding_array=array();
        $encoding_array_values=array("utf-8","windows-1256","iso","asmo-708","dos");// arabic encodings
        $encoding[0]=$this->search_text($text,"charset=utf-8");
        $encoding[1]=$this->search_text($text,"charset=windows-1256");
        $encoding[2]=$this->search_text($text,"charset=iso-6");
        $encoding[3]=$this->search_text($text,"charset=asmo-708");
        $encoding[4]=$this->search_text($text,"charset=dos");
        $i=-1;
        while($i&lt;5)
        {
            $i++;
            if($encoding[$i])
                break;
        }
        $results_array[4]=$encoding_array_values[$i];</p>

<p>        $ar_domain = $this->check_if_arabic($site);
        if($ar_domain==true)// arabic domain
        {
            $results_array[1]="Y";
        }
        else
        if ( ($lang_flag1) || ($lang_flag2) || ($lang_flg3))  // arabic lang tag found
            $results_array[1]="Y";
        else // arabic lang tag not found so check the encoding
        {
            if ($encoding[0]!==false)// UTF-8 encoding 
            {
                $str='?§'; // alef charachter in arabic utf8
                $p=$this->search_text($text,$str);
                if ($p)// arabic lang found
                {
                    $results_array[1]="Y";
                }
                else// other lang found
                {
                    $results_array[1]="N";
                }
            }
            else// Arabic encoding
            if ( ($encoding[1]) || ($encoding[2]) || ($encoding[3]) || ($encoding[4]))
                $results_array[1]="Y";
            else
            {
                $results_array[4]="no arabic encoding";
                $results_array[1]="N";
            }
        }
    }
    else
    {
        $msg="URL does not exist";
        $results_array[0]="N";
    }
    return $results_array;
}

I hope this will help

 
دخول أو تسجيل لإرسال التعليقات
الأحد, 2007/09/09 - 12:04pm
صورة ReBoL

تاريخ التسجيل: 2006-06-21
مشاركات: 131

الجامعة: غير ذلك
الكلية: الهندسة المعلوماتية
المرحلة: السنة الخامسة
الاختصاص: هندسة برمجيات

ممكن أحيانا عن طريق :

<html xmlns="http://www.w3.org/1999/xhtml" lang="ar" xml:lang="ar">

أو ar-sy ...

الحق لا يعرف بالرجال، اعرف الحق تعرف أهله.

 
دخول أو تسجيل لإرسال التعليقات
الأحد, 2007/09/09 - 9:13pm
عضو فعال
صورة iman

تاريخ التسجيل: 2006-12-01
مشاركات: 275

شكرا as_els على الإفادة وبعتقد ما في غير ه الحل والخطأ هيكون بالمواقع اللي كاتبين الهيدرز و الميتا غلط

او ازا بدك ابعتلو لغوغل عنوان الموقع مثلا site:www.nahfa.com وحددله براميتر انه بحث بالصفحات العربية فقط هيك

وازا ما لقى هيقلك انو لم يتم العثور على نتائج متل

هي طريقة غبية شوي بس ازا بدك تريح حالك Wink

How Perfect You are O Allah, and I praise You. LA Ilah Ila Lah, I seek Your forgiveness and turn to You in repentance

 
دخول أو تسجيل لإرسال التعليقات
الأحد, 2007/09/09 - 9:48pm
عضو فعال

تاريخ التسجيل: 2004-03-18
مشاركات: 313

الجامعة: غير ذلك
الكلية: الهندسة المعلوماتية
المرحلة: ماجستير
الاختصاص: ذكاء صنعي

as_els thanks for the information.
It seems ,as you said, that there is no way to know the language form the http headers.
one needs unfortunately to download the page and process it.
This will put a lot of effort on my crawler.
Anyway, thanks for help.

 
دخول أو تسجيل لإرسال التعليقات
الإثنين, 2007/09/10 - 10:22am
صورة as_els

تاريخ التسجيل: 2005-02-20
مشاركات: 248

الجامعة: دمشق
المرحلة: متخرج
الاختصاص: هندسة شبكات

You're welcome guys
you don't have to download the page locally, u can make the crawler get the page content live, and u can use regex in your search to enhance the algorithm, but although this needs some time

 
دخول أو تسجيل لإرسال التعليقات