Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6630081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:21:08+00:00 2026-05-25T22:21:08+00:00

After plumbing the documentation/past questions on list operations, I’ve come up blank – many

  • 0

After plumbing the documentation/past questions on list operations, I’ve come up blank – many of the cases involve numbers, whereas I’m working with large quantities of text.

I have a sorted list of common three-word phrases (trigrams) that appear in a large body of textual information, generated through Mathematica’s Partition[], Tally[], and Sort[] commands. An example of the sort of data that I’m operating on (I have hundreds of these files):

{{{wa, wa, wa}, 66}, {{i, love, you}, 62}, {{la, la, la}, 50}, {{meaning, of, life}, 42}, {on, come, on}, 40}, {{come, on, come}, 40}, {{yeah, yeah, yeah}, 38}, {{no, no, no}, 36}, {{we, re, gonna}, 36}, {{you, love, me}, 35}, {{in, love, with}, 32}, {{the, way, you}, 30}, {{i, want, to}, 30}, {{back, to, me}, 29}, <<38211>>, {{of, an, xke}, 1}}

I’m hoping to search this file so that if the input is “meaning, of, life” it will return “42.” I feel like I must be overlooking something obvious but after tinkering around I’ve hit a brick wall here. Mathematica is number heavy in its documentation, which is.. well, unsurprising.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:21:09+00:00Added an answer on May 25, 2026 at 10:21 pm

    Assuming that you can load your data into Mathematica in the form you outlined, one very simple thing to do is to create a hash-table, where your trigrams will be the (compound) keys. Here is your sample (the part of it that you gave):

    trigrams = {{{"wa", "wa", "wa"}, 66}, {{"i", "love", "you"}, 62}, 
     {{"la", "la", "la"}, 50}, {{"meaning", "of", "life"}, 42}, 
     {{"on", "come", "on"}, 40}, {{"come", "on", "come"}, 40}, 
     {{"yeah", "yeah", "yeah"}, 38}, {{"no", "no", "no"}, 36}, 
     {{"we", "re", "gonna"}, 36}, {{"you", "love", "me"}, 35}, 
     {{"in", "love", "with"}, 32}, {{"the", "way", "you"}, 30}, 
     {{"i", "want", "to"}, 30}, {{"back", "to", "me"}, 29}, 
     {{"of", "an", "xke"}, 1}};
    

    Here is one possible way to create a hash-table:

    Clear[trigramHash];
    (trigramHash[Sequence @@ #1] = #2) & @@@ trigrams;
    

    Now, we use it like

    In[16]:= trigramHash["meaning","of","life"]
    Out[16]= 42
    

    This approach will be beneficial if you perform many searches, of course.

    EDIT

    If you have many files and want to search them efficiently in Mathematica, one thing you could do is to use the above hashing mechanism to convert all your files to .mx binary Mathematica files. These files are optimized for fast loading, and serve as a persistence mechanism for definitions you want to store. Here is how it may work:

    In[20]:= DumpSave["C:\\Temp\\trigrams.mx",trigramHash]
    Out[20]= {trigramHash}
    
    In[21]:= Quit[]
    
    In[1]:= Get["C:\\Temp\\trigrams.mx"]
    In[2]:= trigramHash["meaning","of","life"]
    Out[2]= 42
    

    You use DumpSave to create an .mx file. So, the suggested procedure is to load your data into Mathematica, file by file, create hashes (you could use SubValues to index a particular hash-table with an index of your file), and then save those definitions into .mx files. In this way, you get fast load and fast search, and you have a freedom to decide which part of your data to keep loaded into Mathematica at any given time (pretty much without a performance hit, normally associated with file loading).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After much Google searching and at the risk of asking dumb questions, I could
after some advice really. My app fills a list view on load using a
After deploying WCF server (svc) on my Server, I have got this message when
After discovering about Javascript namespaces, I tried to implement them but I run into
After a system upgrade i am no longer able to start my tomcat5 server.
After some time researching and trying different things I still cannot get my @ExceptionHandler
After following the RoR getting started tutorial, I added another model as: $ rails
After adding Restkit to the Podfile : platform :ios dependency 'Facebook-iOS-SDK', '1.2' dependency 'RestKit',
After a long search I'm still confused about it although I found some related
After I click update in the grid view, the code works successfully. But when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.