pip install multi-rake في حالة فشل التثبيت بسبب narrowing conversions خطأ cld ، مما يمكن تثبيته به
CFLAGS= " -Wno-narrowing " pip install multi-rakeالنص الإنجليزي ، نحن لا نحدد لغة صريحة ولا قائمة من الكلمات الموقف (يتم استخدام القائمة المدمجة).
from multi_rake import Rake
text_en = (
'Compatibility of systems of linear constraints over the set of '
'natural numbers. Criteria of compatibility of a system of linear '
'Diophantine equations, strict inequations, and nonstrict inequations '
'are considered. Upper bounds for components of a minimal set of '
'solutions and algorithms of construction of minimal generating sets '
'of solutions for all types of systems are given. These criteria and '
'the corresponding algorithms for constructing a minimal supporting '
'set of solutions can be used in solving all the considered types of '
'systems and systems of mixed types.'
)
rake = Rake ()
keywords = rake . apply ( text_en )
print ( keywords [: 10 ])
# ('minimal generating sets', 8.666666666666666),
# ('linear diophantine equations', 8.5),
# ('minimal supporting set', 7.666666666666666),
# ('minimal set', 4.666666666666666),
# ('linear constraints', 4.5),
# ('natural numbers', 4.0),
# ('strict inequations', 4.0),
# ('nonstrict inequations', 4.0),
# ('upper bounds', 4.0),
# ('mixed types', 3.666666666666667),نص مكتوب في إسبرانتو (مقال عن الليبرالية). لا توجد قائمة بالكلمات المحدودة لهذه اللغة ، وسيتم إنشاءها من النص المقدم.
يتكون text من ثلاث فقرات أولى من المقدمة. text_for_stopwords - جميع النصوص الأخرى.
text = (
'Liberalismo estas politika filozofio aŭ mondrigardo konstruita en '
'ideoj de libereco kaj egaleco. Liberaluloj apogas larĝan aron de '
'vidpunktoj depende de sia kompreno de tiuj principoj, sed ĝenerale '
'ili apogas ideojn kiel ekzemple liberaj kaj justaj elektoj, '
'civitanrajtoj, gazetara libereco, religia libereco, libera komerco, '
'kaj privata posedrajto. Liberalismo unue iĝis klara politika movado '
'dum la Klerismo, kiam ĝi iĝis populara inter filozofoj kaj '
'ekonomikistoj en la okcidenta mondo. Liberalismo malaprobis heredajn '
'privilegiojn, ŝtatan religion, absolutan monarkion kaj la Didevena '
'Rajto de Reĝoj. La filozofo John Locke de la 17-a jarcento ofte '
'estas meritigita pro fondado de liberalismo kiel klara filozofia '
'tradicio. Locke argumentis ke ĉiu homo havas naturon rekte al vivo, '
'libereco kaj posedrajto kaj laŭ la socia '
'kontrakto, registaroj ne rajtas malobservi tiujn rajtojn. '
'Liberaluloj kontraŭbatalis tradician konservativismon kaj serĉis '
'anstataŭigi absolutismon en registaroj per reprezenta demokratio kaj '
'la jura hegemonio.'
)
rake = Rake ( max_words_unknown_lang = 3 )
keywords = rake . apply ( text , text_for_stopwords = other_text )
print ( keywords )
# ('serĉis anstataŭigi absolutismon', 9.0) # sought to replace absolutism
# ('filozofo john locke', 8.5), # philosopher John Locke
# ('locke argumentis', 4.5) # Locke argues
# ('justaj elektoj', 4.0), # fair elections
# ('libera komerco', 4.0), # free trade
# ('okcidenta mondo', 4.0), # western world
# ('ŝtatan religion', 4.0), # state religion
# ('absolutan monarkion', 4.0), # absolute monarchy
# ('didevena rajto', 4.0), # Dominican Rights
# ('socia kontrakto', 4.0), # social contract
# ('jura hegemonio', 4.0), # legal hegemony
# ('mondrigardo konstruita', 4.0) # worldview built
# ('vidpunktoj depende', 4.0), # views based
# ('sia kompreno', 4.0), # their understanding
# ('tiuj principoj', 4.0), # these principles
# ('gazetara libereco', 3.5), # freedom of press
# ('religia libereco', 3.5), # religious freedom
# ('privata posedrajto', 3.5), # private property
# ('libereco', 1.5), # liberty
# ('posedrajto', 1.5)] # propertyلذلك ، نحن قادرون على الحصول على نتيجة لائقة دون مجموعة صريحة من كلمات التوقف.
تهيئة كائن أشعل النار
from multi_rake import Rake
rake = Rake (
min_chars = 3 ,
max_words = 3 ,
min_freq = 1 ,
language_code = None , # 'en'
stopwords = None , # {'and', 'of'}
lang_detect_threshold = 50 ,
max_words_unknown_lang = 2 ,
generated_stopwords_percentile = 80 ,
generated_stopwords_max_len = 3 ,
generated_stopwords_min_freq = 2 ,
)min_chars - يتم تحديد كلمة لتكون جزءًا من الكلمة الرئيسية إذا كان طولها> = min_chars. الافتراضي 3
Max_Words - الحد الأقصى لعدد الكلمات في العبارة التي تعتبر كلمة رئيسية. الافتراضي 3
MIN_FREQ - الحد الأدنى لعدد الحالات من العبارة التي تعتبر كلمة رئيسية. الافتراضي 1
language_code - وفر رمز اللغة كسلسلة لاستخدام مجموعة مضمنة من الكلمات المتوقفة. انظر قائمة اللغات المتاحة. إذا لم يتم تحديد اللغة ، فستحاول الخوارزمية تحديد اللغة باستخدام CLD2 واستخدام مجموعة المقابلة من الكلمات المدمجة. الافتراضي لا شيء
Stopwords - توفير مجموعة خاصة من كلمات التوقف (ويفضل أن تكون محددة ، منخفضة). يتجاوز language_code إذا تم تحديده. الافتراضي لا شيء
حافظ على language_code و stopwords حيث سيتم إنشاء None والكلمات المتوقفة من النص المقدم.
lang_detect_threshold - عتبة احتمال اللغة المكتشفة في CLD2 (0-100). الافتراضي 50
max_words_unknown_lang - نفس max_words ولكن سيتم استخدامه إذا كانت اللغة غير معروفة وتم إنشاء كلمات التوقف من النص المقدم. عادةً ما يتم الحصول على أفضل نتيجة عند استخدام مجموعة من كلمات التوقف المحددة على وجه التحديد ، في حالة غيابها واستخدام كلمات التوقف التي تم إنشاؤها الناتجة عن الكلمات الرئيسية التي قد تكون جميلة وقد تكون فكرة جيدة ، على سبيل المثال ، لإنتاج الكلمات الرئيسية المكونة من كلمتين لللغات غير المعروفة والكلمات الرئيسية المكونة من 3 كلمات لللغات التي تحتوي على مجموعات محددة من الكلمات. الافتراضي 2
enderated_stopwords_percentile - لإنشاء كلمات توقف نقوم بإنشاء توزيع لكل كلمة في النص عن طريق التردد. سيتم اعتبار الكلمات فوق هذه النسبة المئوية (0 - 100) مرشحين ليصبحوا كلمات توقف. الافتراضي 80
enderated_stopwords_max_len - الحد الأقصى لطول الحرف من كلمات التوقف التي تم إنشاؤها. الافتراضي 3
enderated_stopwords_min_freq - الحد الأدنى من ترددات التوقف التي تم إنشاؤها في التوزيع. الافتراضي 2
تطبيق كائن Rake على النص.
keywords = rake . apply (
text ,
text_for_stopwords = None ,
)النص - سلسلة تحتوي على نص يجب أن يتم إنشاء الكلمات الرئيسية منها.
text_for_stopwords - سلسلة تحتوي على نص سيتم استخدامها لتوليد كلمات StopWord إلى جانب text . على سبيل المثال ، لديك مقالة مع مقدمة وعدة أقسام فرعية. أنت تعلم أنه لأغراضك ، ستكون كلماتك الرئيسية من مقدمة كافية ، فأنت لا تعرف لغة النص ولا لديك قائمة بالكلمات المحدودة. لذلك يمكن إنشاء كلمات التوقف من النص نفسه والمزيد من النص لديك ، كان ذلك أفضل. مما يمكنك تحديد text=introduction, text_for_stopwords=rest_of_your_text .
تعمل خوارزمية Rake Conship في Rose ، S. ، Engel ، D. ، Cramer ، N. ، & Cowley ، W. (2010). استخراج الكلمات الرئيسية التلقائي من المستندات الفردية. في MW Berry & J. Kogan (محرران) ، تعدين النص: النظرية والتطبيقات: John Wiley & Sons
هذا التنفيذ يختلف عن الآخرين من خلال دعمه متعدد اللغات. في الأساس ، قد تقدم نصًا دون معرفة لغته (يجب أن تتم كتابتها بالأبجدية السيريلية أو اللاتينية) ، دون قائمة صريحة من الكلمات المتوقفة والحصول على نتيجة لائقة. على الرغم من تحقيق أفضل نتيجة من خلال قائمة مخصصة بدقة من كلمات التوقف.
ما يحدث تحت الغطاء:
text و text_for_stopwords نقوم بإنشاء كلمات Stopwords عن طريق إنشاء توزيع التردد للكلمات في النص وتصفيةها باستخدام المعلمات generated_stopwords_percentile ، generated_stopwords_max_len ، generated_stopwords_min_freq . لن نكون قادرين على توليدها بشكل مثالي ، لكن من السهل العثور على مقالات وحرارة الجر ، لأنها عادة ما تتكون من 3-4 أحرف وتظهر بشكل متكرر. تتيح لنا هذه الكلمات المتوقفة ، إلى جانب محددات علامات الترقيم ، الحصول على نتائج لائقة للغات التي لا نفهمها.
أثناء تهيئة أشعل النار ، يجب استخدام رمز اللغة فقط.
قام المستودع بتكوين Linter والاختبارات والتغطية.
قم بإنشاء بيئة افتراضية جديدة داخل مجلد Multi_Rake لاستخدامها.
python3 -m venv env
source env/bin/activate
make install-dev # install dependencies
make lint # run linter
make test # run tests and coverage خوارزمية Rake: Rose ، S. ، Engel ، D. ، Cramer ، N. ، & Cowley ، W. (2010). استخراج الكلمات الرئيسية التلقائي من المستندات الفردية. في MW Berry & J. Kogan (محرران) ، تعدين النص: النظرية والتطبيقات: John Wiley & Sons
كأساس تم استخدام تنفيذ أشعل النار من قبل Fabianvf.
Stopwords: Trec-KBA ، يحتل المرتبة NL