2014-06-17 17 views
6

Có cách nào tốt nhất để bình thường hóa tiếng Anh Anh và Mỹ trong Elasticsearch?Bình thường hóa Anh và Mỹ Anh cho Elasticsearch

Sử dụng Synonym Token Filter yêu cầu tệp cấu hình cực kỳ dài. Thực tế, có hàng ngàn từ được đánh vần khác nhau bằng tiếng Anh và tiếng Anh Mỹ và hầu như không thể tìm thấy một danh sách các từ thực sự toàn diện. Đây là một list of almost 2.000 words, nhưng nó chưa được hoàn thành.

Tốt hơn, tôi muốn tạo ES Analyzer/Filter với rules to transform US to UK tiếng Anh. Có lẽ đó là cách tiếp cận tốt hơn, nhưng tôi không biết bắt đầu từ đâu - loại bộ lọc nào tôi cần cho điều đó? Nó không phải bao gồm tất cả mọi thứ - nó chỉ nên bình thường hóa hầu hết các từ tìm kiếm. Ví dụ. "xám" - "màu xám", "màu" - "màu", "trung tâm" - "trung tâm", v.v.

Trả lời

2

Đây là cách tiếp cận mà tôi đã đi sau khi không sử dụng trong một khoảng thời gian. Đó là sự kết hợp của các quy tắc cơ bản, "sửa lỗi" và từ đồng nghĩa: Trước tiên, áp dụng một char_filter để thực thi một bộ quy tắc chính tả cơ bản. Nó không chính xác 100%, nhưng nó thực hiện công việc khá tốt:

"char_filter": { 
    "en_char_filter": { "type": "mapping", "mappings": [ 
     # fixes 
     "aerie=>axerie", "aeroplane=>airplane", "aloe=>aloxe", "canoe=>canoxe", "coerce=>coxerce", "poem=>poxem", "prise=>prixse", 
     # whole words 
     "armour=>armor", "behaviour=>behavior", "centre=>center" "colour=>color", "clamour=>clamor", "draught=>draft", "endeavour=>endeavor", "favour=>favor", "flavour=>flavor", "harbour=>harbor", "honour=>honor", 
     "humour=>humor", "labour=>labor", "litre=>liter", "metre=>meter", "mould=>mold", "neighbour=>neighbor", "plough=>plow", "saviour=>savior", "savour=>savor", 
     # generic transformations 
     "ae=>e", "ction=>xion", "disc=>disk", "gramme=>gram", "isable=>izable", "isation=>ization", "ise=>ize", "ising=>izing", "ll=>l", "oe=>e", "ogue=>og", "sation=>zation", "yse=>yze", "ysing=>yzing" 
    ] } 
} 

Mục "sửa lỗi" có để ngăn chặn việc áp dụng sai các quy tắc khác. Ví dụ. "prise=>prixse" ngăn "giải thưởng" bị thay đổi thành "giải thưởng", có ý nghĩa khác. Bạn có thể cần phải thích ứng với điều này theo nhu cầu của riêng bạn.

Tiếp theo, bao gồm một bộ lọc từ đồng nghĩa với đánh bắt các ngoại lệ thường xuyên nhất được sử dụng:

"en_synonym_filter": { "type": "synonym", "synonyms": EN_SYNONYMS } 

Dưới đây là danh sách của chúng ta về từ đồng nghĩa trong đó bao gồm các từ khóa quan trọng nhất đối với trường hợp sử dụng của chúng tôi. Bạn có thể muốn điều chỉnh danh sách này với nhu cầu của bạn:

EN_SYNONYMS = (
    "accolade, prize => award", 
    "accoutrement => accouterment", 
    "aching, pain => hurt", 
    "acw, anticlockwise, counterclockwise, counter-clockwise => ccw", 
    "adaptor => adapter", 
    "advocate, attorney, barrister, procurator, solicitor => lawyer", 
    "ageing => aging", 
    "agendas, agendum => agenda", 
    "almanack => almanac", 
    "aluminium => aluminum", 
    "america, united states, usa", 
    "amphitheatre => amphitheater", 
    "anti-aliased, anti-aliasing => antialiased", 
    "arbour => arbor", 
    "ardour => ardor", 
    "arse => ass", 
    "artefact => artifact", 
    "aubergine => eggplant", 
    "automobile, motorcar => car", 
    "axe => ax", 
    "bannister => banister", 
    "barbecue => bbq", 
    "battleaxe => battleax", 
    "baulk => balk", 
    "beetroot => beet", 
    "biassed => biased", 
    "biassing => biasing", 
    "biscuit => cookie", 
    "black american, african american, afro-american, negro", 
    "bobsleigh => bobsled", 
    "bonnet => hood", 
    "bulb, electric bulb, light bulb, lightbulb", 
    "burned => burnt", 
    "bussines, bussiness => business", 
    "business man, business people, businessman", 
    "business woman, business people, businesswoman", 
    "bussing => busing", 
    "cactus, cactuses => cacti", 
    "calibre => caliber", 
    "candour => candor", 
    "candy floss, candyfloss, cotton candy", 
    "car park, parking area, parking ground, parking lot, parking-lot, parking place, parking", 
    "carburettor => carburetor", 
    "castor => caster", 
    "cataloguing => cataloging", 
    "catboat, sailboat, sailing boat", 
    "champion, gainer, victor, win, winner => victory", 
    "chat => talk", 
    "chequebook => checkbook", 
    "chequer => checker", 
    "chequerboard => checkerboard", 
    "chequered => checkered", 
    "christmas tree ball, christmas tree ball ornament, christmas ball ornament, christmas bauble", 
    "christmas, x-mas => xmas", 
    "cinema => movies", 
    "clangour => clangor", 
    "clarinettist => clarinetist", 
    "conditioning => conditioner", 
    "conference => meeting", 
    "coriander => cilantro", 
    "corporate => company", 
    "cosmos, universe => outer space", 
    "cosy, cosiness => cozy", 
    "criminal => crime", 
    "curriculums => curricula", 
    "cypher => cipher", 
    "daddy, father, pa, papa => dad", 
    "defence => defense", 
    "defenceless => defenseless", 
    "demeanour => demeanor", 
    "departure platform, station platform, train platform, train station", 
    "dishrag => dish cloth", 
    "dishtowel, dishcloth => dish towel", 
    "doughnut => donut", 
    "downspout => drainpipe", 
    "drugstore => pharmacy", 
    "e-mail => email", 
    "enamoured => enamored", 
    "england => britain", 
    "english => british", 
    "epaulette => epaulet", 
    "exercise, excercise, training, workout => fitness", 
    "expressway, motorway, highway => freeway", 
    "facebook => facebook, social media", 
    "fanny => buttocks", 
    "fanny pack => bum bag", 
    "farmyard => barnyard", 
    "faucet => tap", 
    "fervour => fervor", 
    "fibre => fiber", 
    "fibreglass => fiberglass", 
    "flashlight => torch", 
    "flautist => flutist", 
    "flier => flyer", 
    "flower fly, hoverfly, syrphid fly, syrphus fly", 
    "foot-walk, sidewalk, sideway => pavement", 
    "football, soccer", 
    "forums => fora", 
    "fourth => 4", 
    "freshman => fresher", 
    "chips, fries, french fries", 
    "gaol => jail", 
    "gaolbird => jailbird", 
    "gaolbreak => jailbreak", 
    "gaoler => jailer", 
    "garbage, rubbish => trash", 
    "gasoline => petrol", 
    "gases, gasses", 
    "gauge => gage", 
    "gauged => gaged", 
    "gauging => gaging", 
    "gipsy, gipsies, gypsies => gypsy", 
    "glamour => glamor", 
    "glueing => gluing", 
    "gravesite, sepulchre, sepulture => sepulcher", 
    "grey => gray", 
    "greyish => grayish", 
    "greyness => grayness", 
    "groyne => groin", 
    "gryphon, griffon => griffin", 
    "hand shake, shake hands, shaking hands, handshake", 
    "haulier => hauler", 
    "hobo, homeless, tramp => bum", 
    "new year, new year's eve, hogmanay, silvester, sylvester", 
    "holiday => vacation", 
    "holidaymaker, holiday-maker, vacationer, vacationist => tourist", 
    "homosexual, fag => gay", 
    "inbox, letterbox, outbox, postbox => mailbox", 
    "independence day, 4th of july, fourth of july, july 4th, july 4, 4th july, july fourth, forth of july, 4 july, fourth july, 4th july", 
    "infant, suckling, toddler => baby", 
    "infeasible => unfeasible", 
    "inquire, inquiry => enquire", 
    "insure => ensure", 
    "internet, website => www", 
    "jelly => jam", 
    "jewelery, jewellery => jewelry", 
    "jogging => running", 
    "journey => travel", 
    "judgement => judgment", 
    "kerb => curb", 
    "kiwifruit => kiwi", 
    "laborer => worker", 
    "lacklustre => lackluster", 
    "ladybeetle, ladybird, ladybug => ladybird beetle", 
    "larrikin, scalawag, rascal, scallywag => naughty boy", 
    "leaf => leaves", 
    "licence, licenced, licencing => license", 
    "liquorice => licorice", 
    "lorry => truck", 
    "loupe, magnifier, magnifying, magnifying glass, magnifying lens, zoom", 
    "louvred => louvered", 
    "louvres => louver", 
    "lustre => luster", 
    "mail => post", 
    "mailman => postman", 
    "marriage, married, marry, marrying, wedding => wed", 
    "mayonaise => mayo", 
    "meagre => meager", 
    "misdemeanour => misdemeanor", 
    "mitre => miter", 
    "mom, momma, mummy, mother => mum", 
    "moonlight => moon light", 
    "moult => molt", 
    "moustache, moustached => mustache", 
    "nappy => diaper", 
    "nightlife => night life", 
    "normalcy => normality", 
    "octopus => kraken", 
    "odour => odor", 
    "odourless => odorless", 
    "offence => offense", 
    "omelette => omelet", 
    "# fix torres del paine", 
    "paine => painee", 
    "pajamas => pyjamas", 
    "pantyhose => tights", 
    "parenthesis, parentheses => bracket", 
    "parliament => congress", 
    "parlour => parlor", 
    "persnickety => pernickety", 
    "philtre => filter", 
    "phoney => phony", 
    "popsicle => iced-lolly", 
    "porch => veranda", 
    "pretence => pretense", 
    "pullover, jumper => sweater", 
    "pyjama => pajama", 
    "railway => railroad", 
    "rancour => rancor", 
    "rappel => abseil", 
    "row house, serial house, terrace house, terraced house, terraced housing, town house", 
    "rigour => rigor", 
    "rumour => rumor", 
    "sabre => saber", 
    "saltpetre => saltpeter", 
    "sanitarium => sanatorium", 
    "santa, santa claus, st nicholas, st nicholas day", 
    "sceptic, sceptical, scepticism, sceptics => skeptic", 
    "sceptre => scepter", 
    "shaikh, sheikh => sheik", 
    "shivaree => charivari", 
    "silverware, flatware => cutlery", 
    "simultaneous => simultanous", 
    "sleigh => sled", 
    "smoulder, smouldering => smolder", 
    "sombre => somber", 
    "speciality => specialty", 
    "spectre => specter", 
    "splendour => splendor", 
    "spoilt => spoiled", 
    "street => road", 
    "streetcar, tramway, tram => trolley-car", 
    "succour => succor", 
    "sulphate, sulphide, sulphur, sulphurous, sulfurous => sulfur", 
    "super hero, superhero => hero", 
    "surname => last name", 
    "sweets => candy", 
    "syphon => siphon", 
    "syphoning => siphoning", 
    "tack, thumb-tack, thumbtack => drawing pin", 
    "tailpipe => exhaust pipe", 
    "taleban => taliban", 
    "teenager => teen", 
    "television => tv", 
    "thank you, thanks", 
    "theatre => theater", 
    "tickbox => checkbox", 
    "ticked => checked", 
    "timetable => schedule", 
    "tinned => canned", 
    "titbit => tidbit", 
    "toffee => taffy", 
    "tonne => ton", 
    "transportation => transport", 
    "trapezium => trapezoid", 
    "trousers => pants", 
    "tumour => tumor", 
    "twitter => twitter, social media", 
    "tyre => tire", 
    "tyres => tires", 
    "undershirt => singlet", 
    "university => college", 
    "upmarket => upscale", 
    "valour => valor", 
    "vapour => vapor", 
    "vigour => vigor", 
    "waggon => wagon", 
    "windscreen, windshield => front shield", 
    "world championship, world cup, worldcup", 
    "worshipper, worshipping => worshiping", 
    "yoghourt, yoghurt => yogurt", 
    "zip, zip code, postal code, postcode", 
    "zucchini => courgette" 
) 
+0

Ngay cả khi nó không phải câu hỏi của tôi. Tôi cảm ơn bạn vì điều này! Một công việc rất tốt. –

1

Tôi nhận ra rằng câu trả lời này khởi hành hơi từ câu hỏi ban đầu của OP, nhưng nếu bạn chỉ muốn bình thường hóa Mỹ vs Anh-Anh chính tả biến thể, bạn có thể nhìn vào đây để xem danh sách có kích thước quản lý (~ 1.700 thay thế): http://www.tysto.com/uk-us-spelling-list.html. Tôi chắc chắn có những người khác ra khỏi đó quá mà bạn có thể sử dụng để tạo ra một danh sách tổng hợp tổng hợp.

Ngoài biến thể chính tả, bạn phải rất cẩn thận để không thay thế các từ một cách cô lập bằng các đối tác (giả định!) Bằng tiếng Anh Mỹ. Tôi sẽ khuyên bạn nên chống lại tất cả nhưng thay thế vững chắc nhất của sự thay thế từ vựng. Ví dụ, tôi không thể nhìn thấy bất cứ điều gì xấu xảy ra từ một

này "ngược, ngược chiều, ngược chiều kim đồng => ngược"

nhưng điều này một

"lang thang, vô gia cư, lang thang => bum "

sẽ lập chỉ mục" Một người đàn ông vô gia cư "=> *" Một người đàn ông bum ", điều đó là vô nghĩa. (Chưa kể rằng hobos, người vô gia cư và "tramps" là khá khác biệt - http://knowledgenuts.com/2014/11/26/the-difference-between-hobos-tramps-and-bums/.)

Tóm lại, ngoài biến thể chính tả, phân chia phương ngữ Mỹ so với tiếng Anh rất phức tạp và không thể giảm xuống dạng danh sách đơn giản -ups.

P.S. Nếu bạn thực sự muốn làm điều này đúng (tức là, tài khoản ngữ cảnh ngữ pháp, v.v.), có thể bạn sẽ cần một mô hình diễn giải theo ngữ cảnh nhạy cảm để "dịch" tiếng Anh sang tiếng Anh Mỹ (hoặc ngược lại, tùy thuộc vào nhu cầu của bạn) trước khi nó chạm vào chỉ mục ES. Điều này có thể được thực hiện (với đầy đủ dữ liệu song song) sử dụng mô hình dịch thống kê có sẵn hoặc thậm chí một số phần mềm trong nhà tùy chỉnh sử dụng phân tích cú pháp ngôn ngữ tự nhiên, gắn thẻ POS, chunking, v.v.

Các vấn đề liên quan