This link包含所有语言维基词典中的所有“专有名称”。这意味着个人名称,如Tatiana,Zadie或Richard。然而,它也包括国家,城镇,河流等名称。
我想提取所有个人姓名的记录。
我想提取的记录要么有字符串“given name”,要么有字符串“surname”(有些同时有)。
比如Fabian这个名字:
{"pos": "name", "wikipedia": ["Fabian (name)"], "head_templates": [{"name": "en-proper noun", "args": {}, "expansion": "Fabian"}], "etymology_text": "From Latin Fabiānus (“belonging to Fabius”), derived from Fabius + -ānus.", "etymology_templates": [{"name": "der", "args": {"1": "en", "2": "la", "3": "Fabiānus", "4": "", "5": "belonging to Fabius"}, "expansion": "Latin Fabiānus (“belonging to Fabius”)"}, {"name": "m", "args": {"1": "la", "2": "Fabius"}, "expansion": "Fabius"}, {"name": "m", "args": {"1": "la", "2": "-ānus"}, "expansion": "-ānus"}], "sounds": [{"ipa": "/ˈfeɪbi.ən/"}, {"audio": "LL-Q1860 (eng)-Vealhurl-Fabian.wav", "text": "Audio (Southern England)", "tags": ["Southern-England"], "ogg_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/2/2b/LL-Q1860_%28eng%29-Vealhurl-Fabian.wav/LL-Q1860_%28eng%29-Vealhurl-Fabian.wav.ogg", "mp3_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/2/2b/LL-Q1860_%28eng%29-Vealhurl-Fabian.wav/LL-Q1860_%28eng%29-Vealhurl-Fabian.wav.mp3"}], "word": "Fabian", "lang": "English", "lang_code": "en", "senses": [{"links": [["given name", "given name"]], "raw_glosses": ["(rare) A male given name from Latin."], "glosses": ["A male given name from Latin."], "tags": ["rare"], "id": "Fabian-en-name-XC4~mcw6", "categories": [{"name": "English given names", "kind": "topical", "parents": ["Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}, {"name": "English male given names", "kind": "topical", "parents": ["Male given names", "Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}], "translations": [{"lang": "Aragonese", "code": "an", "sense": "male given name", "tags": ["masculine"], "word": "Fabián", "_dis1": "96 4"}, {"lang": "Catalan", "code": "ca", "sense": "male given name", "word": "Fabià", "_dis1": "96 4"}, {"lang": "Faroese", "code": "fo", "sense": "male given name", "tags": ["masculine"], "word": "Fabian", "_dis1": "96 4"}, {"lang": "French", "code": "fr", "sense": "male given name", "word": "Fabien", "_dis1": "96 4"}, {"lang": "Galician", "code": "gl", "sense": "male given name", "word": "Fabián", "_dis1": "96 4"}, {"lang": "Galician", "code": "gl", "sense": "male given name", "word": "Fabiano", "_dis1": "96 4"}, {"lang": "Galician", "code": "gl", "sense": "male given name", "word": "Fabio", "_dis1": "96 4"}, {"lang": "German", "code": "de", "sense": "male given name", "tags": ["masculine"], "word": "Fabian", "_dis1": "96 4"}, {"lang": "Hungarian", "code": "hu", "sense": "male given name", "word": "Fábián", "_dis1": "96 4"}, {"lang": "Italian", "code": "it", "sense": "male given name", "word": "Fabiano", "_dis1": "96 4"}, {"lang": "Polish", "code": "pl", "sense": "male given name", "tags": ["masculine", "person"], "word": "Fabian", "_dis1": "96 4"}, {"lang": "Portuguese", "code": "pt", "sense": "male given name", "word": "Fabiano", "_dis1": "96 4"}, {"lang": "Spanish", "code": "es", "sense": "male given name", "word": "Fabián", "_dis1": "96 4"}, {"lang": "Swedish", "code": "sv", "sense": "male given name", "word": "Fabian", "_dis1": "96 4"}]}, {"links": [["surname", "surname"]], "glosses": ["A surname."], "id": "Fabian-en-name-EMUC1F3L", "categories": [{"name": "English surnames", "kind": "other", "parents": [], "source": "w"}]}]}
{"pos": "name", "head_templates": [{"name": "head", "args": {"1": "fo", "2": "proper noun", "g": "m"}, "expansion": "Fabian m"}], "inflection_templates": [{"name": "fo-decl-proper-noun-s-indef", "args": {"1": "Fabian", "2": "Fabian", "3": "Fabiani", "4": "Fabians"}}], "forms": [{"form": "", "source": "declension", "tags": ["table-tags"]}, {"form": "fo-decl-proper-noun-s-indef", "source": "declension", "tags": ["inflection-template"]}, {"form": "Fabian", "tags": ["indefinite", "nominative"], "source": "declension"}, {"form": "Fabian", "tags": ["accusative", "indefinite"], "source": "declension"}, {"form": "Fabiani", "tags": ["dative", "indefinite"], "source": "declension"}, {"form": "Fabians", "tags": ["genitive", "indefinite"], "source": "declension"}], "word": "Fabian", "lang": "Faroese", "lang_code": "fo", "senses": [{"links": [["given name", "given name"]], "glosses": ["a male given name"], "tags": ["masculine"], "id": "Fabian-fo-name-h8YdwBAs", "categories": [{"name": "Faroese given names", "kind": "topical", "parents": ["Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}, {"name": "Faroese male given names", "kind": "topical", "parents": ["Male given names", "Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}]}]}
{"pos": "name", "head_templates": [{"name": "head", "args": {"1": "de", "2": "proper noun", "g": "m"}, "expansion": "Fabian m"}], "etymology_text": "Borrowed from Latin Fabiānus (“belonging to Fabius”).", "etymology_templates": [{"name": "glossary", "args": {"1": "loanword", "2": "Borrowed"}, "expansion": "Borrowed"}, {"name": "bor", "args": {"1": "de", "2": "la", "3": "Fabiānus", "4": "", "5": "belonging to Fabius", "lit": "", "pos": "", "tr": "", "ts": "", "id": "", "sc": "", "g": "", "g2": "", "g3": "", "nocat": "", "sort": ""}, "expansion": "Latin Fabiānus (“belonging to Fabius”)"}, {"name": "bor+", "args": {"1": "de", "2": "la", "3": "Fabiānus", "4": "", "5": "belonging to Fabius"}, "expansion": "Borrowed from Latin Fabiānus (“belonging to Fabius”)"}], "sounds": [{"ipa": "/ˈfaːbian/"}, {"audio": "De-Fabian.ogg", "text": "Audio", "ogg_url": "https://upload.wikimedia.org/wikipedia/commons/c/c9/De-Fabian.ogg", "mp3_url": "https://upload.wikimedia.org/wikipedia/commons/transcoded/c/c9/De-Fabian.ogg/De-Fabian.ogg.mp3"}], "word": "Fabian", "lang": "German", "lang_code": "de", "senses": [{"links": [["given name", "given name"]], "glosses": ["a male given name"], "tags": ["masculine"], "id": "Fabian-de-name-h8YdwBAs", "categories": [{"name": "German given names", "kind": "topical", "parents": ["Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}, {"name": "German male given names", "kind": "topical", "parents": ["Male given names", "Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}]}]}
{"pos": "name", "head_templates": [{"name": "head", "args": {"1": "oc", "2": "proper noun", "head": "", "g": "m", "g2": ""}, "expansion": "Fabian m"}, {"name": "oc-proper noun", "args": {"1": "m"}, "expansion": "Fabian m"}], "word": "Fabian", "lang": "Occitan", "lang_code": "oc", "senses": [{"links": [["given name", "given name"], ["Fabian", "Fabian#English"]], "raw_glosses": ["(Gascony) a male given name, equivalent to English Fabian"], "glosses": ["a male given name, equivalent to English Fabian"], "tags": ["Gascony", "masculine"], "id": "Fabian-oc-name-VtvZQ6Yw", "categories": [{"name": "Gascon", "kind": "other", "parents": [], "source": "w"}, {"name": "Occitan given names", "kind": "topical", "parents": ["Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}, {"name": "Occitan male given names", "kind": "topical", "parents": ["Male given names", "Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}]}]}
{"pos": "name", "head_templates": [{"name": "pl-proper noun", "args": {"1": "m-pr"}, "expansion": "Fabian m pers"}], "inflection_templates": [{"name": "pl-decl-noun-m-pr", "args": {"nomp": "Fabianowie"}}], "forms": [{"form": "", "source": "declension", "tags": ["table-tags"]}, {"form": "pl-decl-noun-m-pr", "source": "declension", "tags": ["inflection-template"]}, {"form": "Fabian", "tags": ["nominative", "singular"], "source": "declension"}, {"form": "Fabianowie", "tags": ["nominative", "plural"], "source": "declension"}, {"form": "Fabiana", "tags": ["genitive", "singular"], "source": "declension"}, {"form": "Fabianów", "tags": ["genitive", "plural"], "source": "declension"}, {"form": "Fabianowi", "tags": ["dative", "singular"], "source": "declension"}, {"form": "Fabianom", "tags": ["dative", "plural"], "source": "declension"}, {"form": "Fabiana", "tags": ["accusative", "singular"], "source": "declension"}, {"form": "Fabianów", "tags": ["accusative", "plural"], "source": "declension"}, {"form": "Fabianem", "tags": ["instrumental", "singular"], "source": "declension"}, {"form": "Fabianami", "tags": ["instrumental", "plural"], "source": "declension"}, {"form": "Fabianie", "tags": ["locative", "singular"], "source": "declension"}, {"form": "Fabianach", "tags": ["locative", "plural"], "source": "declension"}, {"form": "Fabianie", "tags": ["singular", "vocative"], "source": "declension"}, {"form": "Fabianowie", "tags": ["plural", "vocative"], "source": "declension"}], "etymology_text": "Borrowed from Latin Fabianus.", "etymology_templates": [{"name": "glossary", "args": {"1": "loanword", "2": "Borrowed"}, "expansion": "Borrowed"}, {"name": "bor", "args": {"1": "pl", "2": "la", "3": "Fabianus", "4": "", "5": "", "lit": "", "pos": "", "tr": "", "ts": "", "id": "", "sc": "", "g": "", "g2": "", "g3": "", "nocat": "", "sort": ""}, "expansion": "Latin Fabianus"}, {"name": "bor+", "args": {"1": "pl", "2": "la", "3": "Fabianus"}, "expansion": "Borrowed from Latin Fabianus"}], "sounds": [{"ipa": "/ˈfa.bjan/"}, {"rhymes": "-abjan"}], "hyphenation": ["Fa‧bian"], "word": "Fabian", "lang": "Polish", "lang_code": "pl", "senses": [{"links": [["given name", "given name"], ["Fabian", "Fabian#English"]], "glosses": ["a male given name, equivalent to English Fabian"], "tags": ["masculine", "person"], "id": "Fabian-pl-name-VtvZQ6Yw", "categories": [{"name": "Polish given names", "kind": "topical", "parents": ["Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}, {"name": "Polish male given names", "kind": "topical", "parents": ["Male given names", "Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}]}]}
{"pos": "name", "head_templates": [{"name": "head", "args": {"1": "sv", "2": "proper noun", "head": "", "g": "c", "3": "genitive", "4": "Fabians"}, "expansion": "Fabian c (genitive Fabians)"}, {"name": "sv-proper noun", "args": {"1": "c"}, "expansion": "Fabian c (genitive Fabians)"}], "forms": [{"form": "Fabians", "tags": ["genitive"]}], "word": "Fabian", "lang": "Swedish", "lang_code": "sv", "senses": [{"links": [["given name", "given name"]], "glosses": ["a male given name"], "tags": ["common-gender"], "id": "Fabian-sv-name-h8YdwBAs", "categories": [{"name": "Swedish given names", "kind": "topical", "parents": ["Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}, {"name": "Swedish male given names", "kind": "topical", "parents": ["Male given names", "Given names", "Names", "All topics", "Proper nouns", "Terms by semantic function", "Fundamental", "Nouns", "Lemmas"], "source": "w"}]}]}
字符串
作为一个人类,我可以看到 Fabian,链接文件中的第一条记录,从第2行到第7行。第8行是一条新记录。但是我不能计算出一个正则表达式模式,可以让我提取整个记录,比如 Fabian,这是个人的名字。
你能帮忙吗?
1条答案
按热度按时间zazmityj1#
假设输入数据是JSON格式的,最好使用
ConvertFrom-Json
来解析它,这允许您使用Where-Object
来过滤JSON对象的属性:字符串
$personalNameObjects
现在包含[pscustomobject]
示例,这些示例表示那些输入JSON对象,其中.senses.links
属性值包含given name
或surname
(作为 * 子字符串 *,因为存在变体,例如使用复数s
或后缀(如#English
))-可能需要进一步过滤,例如通过条目类型。要获取唯一名称本身(假设它们存储在
.word
属性中),请使用用途:型
注意事项:
[System.IO.File]::ReadLines()
用于提高阅读性能;Get-Content
-LiteralPath names.json
也可以工作,但会明显慢一些。Convert-Path
用于传递输入文件的 full 路径。ConvertTo-Json
将过滤后的从JSON解析的对象转换回JSON;请确保使用足够大的-Depth
参数以防止无意中截断(有关背景信息,请参阅this post)。