Extract all words starting with a specific letter from wordnet

how to extract all words that begin with a specific letter from wordnet. Example, if I type A, wordnet should return all words starting with the letter A.

+3
source share
2 answers

The easiest way is to download their database from here , and then analyze the space-separated data files (data.adj, data.adv, data.noun, data.verb) for the 5th element in each row and put them in the corresponding data structure .

Perhaps a hash table with a start letter as a key and each element as an array of words starting with that letter.

, , ( ), .

C wordnet . .

#include <stdio.h>
#include <string.h>
int main(int argc,char**argv)
{
  FILE *fp;

  fp=fopen("data.noun", "r");
  char line [ 3000 ];
  while ( fgets ( line, sizeof line, fp ) != NULL )
  {
      char *result = NULL;
      int count =0;
      result = (char*)strtok( line, " ");
      count++; 
      while( result != NULL ) 
      {
      if (count == 5) 
      {
          printf( "result is \"%s\"\n", result );
      }
      result = (char*)strtok( NULL, " ");
      count++;
      }
  }
  return 0;
}

WordNet .

API WordNet C , . findtheinfo, , , , , API.

+3

python .tab Open Multilingual Wordnet :

# Read Open Multi WN .tab file
def readWNfile(wnfile, option="ss"):
  reader = codecs.open(wnfile, "r", "utf8").readlines()
  wn = {}
  for l in reader:
    if l[0] == "#": continue
    if option=="ss":
      k = l.split("\t")[0] #ss as key
      v = l.split("\t")[2][:-1] #word
    else:
      v = l.split("\t")[0] #ss as value
      k = l.split("\t")[2][:-1] #word as key
    try:
      temp = wn[k]
      wn[k] = temp + ";" + v
    except KeyError:
      wn[k] = v  
  return wn

princetonWN = readWNfile('wn-data-eng.tab', 'word')

for i in princetonWN:
    if i[0] == "a":
        print i, princetonWN[i].split(";")
+1
source

Source: https://habr.com/ru/post/1758506/


All Articles