FaizonZaman/LexicalCases

(1.1.0) current version: 1.4.2 »

Extract lexical patterns from text

Contributed By: Faizon Zaman

Search text for lexical patterns. While similar to StringCases, TextCases etc., content types can be used freely in a StringExpression (as opposed to expressing complex lexical patterns in a Containing wrapper). Files, search index objects, and Wikipedia queries are supported. Results are returned in a summary object which supports several subvalues. Consult the documentation for usage.

Installation Instructions

To install this paclet in your Wolfram Language environment, evaluate this code:
PacletInstall["FaizonZaman/LexicalCases"]

Details

I developed this functionality for a particular work task (Lexical Programmer @ Wolfram|Alpha). I needed to find adjectives that precede certain phrases. I started by gathering article text from Wikipedia of relevant domains, then searched for the desired lexical sequences. The initial approach used TextCases and TextContents with the Containing wrapper, (Containing["AdjectivePhrase",Verbatim["music"]] for example), but it was slow. So I designed some lexical tokens I could use in a StringExpression that could be used with StringCases.
TextCases is used internally to extract examples of a content type from the source text. These examples then replace the TextType in the StringExpression. You can see the lexical pattern generated from a piece of text with ExpandPattern. Note that this means, for example, if you have TextType["Adjective"] in your lexical pattern, the token will be replaced by all text snippets identified as adjectives in the source text.
I’d also like to say thanks to Swastik Banerjee for helping me improve SearchIndexObject support!

Paclet Guide

Examples

Basic Examples (1) 

Search for verb phrases beginning with "Alice" in "Alice in Wonderland":

In[1]:=
alice = ExampleData[{"Text", "AliceInWonderland"}];
In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/c0151664-22f4-4aff-bb44-53aa823e7bfd"]
Out[2]=
In[3]:=
aliceVbAvb["Dataset"]
Out[3]=
In[4]:=
aliceVbAvb["CountGroups"]
Out[4]=

Scope (2) 

Search for a lexical pattern in Wikipedia articles containing "darwin":

In[5]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/47480dbd-8b60-4394-8a81-87a37fcef76b"]
In[6]:=
darwin["CountGroups"]
Out[6]=

Search over index objects:

In[7]:=
exampleDataIndex = CreateSearchIndex["ExampleData/Text"]
Out[7]=
In[8]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/1603651c-b594-4c23-baa2-f4887263e0fe"]
Out[8]=

Publisher

Faizon Zaman

Disclosures

Compatibility

Wolfram Language Version 12.3

Version History

  • 1.4.2 – 17 January 2023
  • 1.4.1 – 17 January 2023
  • 1.4.0 – 17 January 2023
  • 1.3.0 – 12 December 2022
  • 1.2.1 – 15 September 2022
  • 1.2.0 – 15 September 2022
  • 1.1.2 – 15 September 2022
  • 1.1.0 – 12 September 2022
  • 1.0.5 – 26 July 2022
  • 1.0.4 – 25 July 2022
  • 1.0.3 – 25 July 2022
  • 1.0.2 – 25 July 2022
  • 1.0.1 – 19 July 2022
  • 1.0.0 – 19 July 2022

License Information

MIT License

Paclet Source

Source Metadata