Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript definitions #7

Open
joelle-o-world opened this issue Nov 2, 2020 · 4 comments
Open

TypeScript definitions #7

joelle-o-world opened this issue Nov 2, 2020 · 4 comments

Comments

@joelle-o-world
Copy link

Hello,

I've been using this module a lot recently and I wrote some ambient ts definitions for it:

type SynsetType = 'noun' | 'verb' | 'adjective' | 'adjective satellite' | 'adverb';
type ShortSynsetType = 'n'|'v'|'a'|'s'|'r';

/**
 * !    Antonym
 * @    Hypernym
 * @i    Instance Hypernym
 * ~    Hyponym
 * ~i    Instance Hyponym
 * #m    Member holonym
 * #s    Substance holonym
 * #p    Part holonym
 * %m    Member meronym
 * %s    Substance meronym
 * %p    Part meronym
 * =    Attribute
 * +    Derivationally related form
 * ;c    Domain of synset - TOPIC
 * -c    Member of this domain - TOPIC
 * ;r    Domain of synset - REGION
 * -r    Member of this domain - REGION
 * ;u    Domain of synset - USAGE
 * -u    Member of this domain - USAGE
 */
type NounPointerSymbol = '!'|'@'|'@i'|'~'|'~i'|'#m'|'#s'|'#p'|'%m'|'%s'|'%p'|'='|'+'|';c'|'-c'|';r'|'-r'|';u'|'-u';


/**
 * !    Antonym 
 * @    Hypernym 
 *  ~    Hyponym 
 * *    Entailment 
 * >    Cause 
 * ^    Also see 
 * $    Verb Group 
 * +    Derivationally related form         
 * ;c    Domain of synset - TOPIC 
 * ;r    Domain of synset - REGION 
 * ;u    Domain of synset - USAGE  
 */
type VerbPointerSymbol = '!'|'@'|'~'|'*'|'>'|'^'|'$'|'+'|';c'|';r'|';u';

/**
 * !    Antonym 
 * &    Similar to 
 * <    Participle of verb 
 * \    Pertainym (pertains to noun) 
 * =    Attribute 
 * ^    Also see 
 * ;c    Domain of synset - TOPIC 
 * ;r    Domain of synset - REGION 
 * ;u    Domain of synset - USAGE
*/
type AdjectivePointerSymbol = '!'|'&'|'<'|'\\'|'='|'^'|';c'|';r'|';u';

/**
 * !    Antonym 
 * \    Derived from adjective 
 * ;c    Domain of synset - TOPIC 
 * ;r    Domain of synset - REGION 
 * ;u    Domain of synset - USAGE
*/
type AdverbPointerSymbol = '!'|'/'|';r'|';r'|';u';

type PointerSymbol = NounPointerSymbol | VerbPointerSymbol | AdverbPointerSymbol | AdjectivePointerSymbol;

type Definition = {
  meta: {
    synsetOffset: number;
    lexFilenum: number;
    synsetType: SynsetType;
    wordCount: number;
    words: {word: string; lexId:number}[];
    pointerCount: number;
    pointers: {
      pointerSymbol: PointerSymbol;
      synsetOffset: number;
      /** Part of speech */
      pos: ShortSynsetType;
      sourceTargetHex: string;
      data: Definition;
    }[];
  };
  glossary: string;
}[];

declare module 'wordnet' {
  /**
   * Lists all the words.
   *
   * @param {Function} callback Std callback with error and list of words.
   */
  export function list(callback: (error:any, result?:string[]) => void):void;

  /**
   * Looks up a word
   *
   * @param {String} word Word to look up.
   * @param {Function} callback Std callback with error and definition.
   */
  export function lookup(
    word:string, 
    callback: (err:any, definition:Definition) => void
  ):void;
}
@joelle-o-world
Copy link
Author

Note, this is based on the latest version published on npm and doesn't match latest version here in github.

@JeffMII
Copy link

JeffMII commented Feb 11, 2022

I agree. Types would be a nice addition.

@JeffMII
Copy link

JeffMII commented Feb 11, 2022

@joelyjoel I updated the type declarations to match the newest version on npm.

type SynsetType = 'noun' | 'verb' | 'adjective' | 'adjective satellite' | 'adverb';
type ShortSynsetType = 'n'|'v'|'a'|'s'|'r';

/**
 * !    Antonym
 * @    Hypernym
 * @i    Instance Hypernym
 * ~    Hyponym
 * ~i    Instance Hyponym
 * #m    Member holonym
 * #s    Substance holonym
 * #p    Part holonym
 * %m    Member meronym
 * %s    Substance meronym
 * %p    Part meronym
 * =    Attribute
 * +    Derivationally related form
 * ;c    Domain of synset - TOPIC
 * -c    Member of this domain - TOPIC
 * ;r    Domain of synset - REGION
 * -r    Member of this domain - REGION
 * ;u    Domain of synset - USAGE
 * -u    Member of this domain - USAGE
 */
type NounPointerSymbol = '!'|'@'|'@i'|'~'|'~i'|'#m'|'#s'|'#p'|'%m'|'%s'|'%p'|'='|'+'|';c'|'-c'|';r'|'-r'|';u'|'-u';

/**
 * !    Antonym 
 * @    Hypernym 
 *  ~    Hyponym 
 * *    Entailment 
 * >    Cause 
 * ^    Also see 
 * $    Verb Group 
 * +    Derivationally related form         
 * ;c    Domain of synset - TOPIC 
 * ;r    Domain of synset - REGION 
 * ;u    Domain of synset - USAGE  
 */
type VerbPointerSymbol = '!'|'@'|'~'|'*'|'>'|'^'|'$'|'+'|';c'|';r'|';u';

/**
 * !    Antonym 
 * &    Similar to 
 * <    Participle of verb 
 * \    Pertainym (pertains to noun) 
 * =    Attribute 
 * ^    Also see 
 * ;c    Domain of synset - TOPIC 
 * ;r    Domain of synset - REGION 
 * ;u    Domain of synset - USAGE
*/
type AdjectivePointerSymbol = '!'|'&'|'<'|'\\'|'='|'^'|';c'|';r'|';u';

/**
 * !    Antonym 
 * \    Derived from adjective 
 * ;c    Domain of synset - TOPIC 
 * ;r    Domain of synset - REGION 
 * ;u    Domain of synset - USAGE
*/
type AdverbPointerSymbol = '!'|'/'|';r'|';r'|';u';

type PointerSymbol = NounPointerSymbol | VerbPointerSymbol | AdverbPointerSymbol | AdjectivePointerSymbol;

type Definition = {
  meta: {
    synsetOffset: number;
    lexFilenum: number;
    synsetType: SynsetType;
    wordCount: number;
    words: {word: string; lexId:number}[];
    pointerCount: number;
    pointers: {
      pointerSymbol: PointerSymbol;
      synsetOffset: number;
      /** Part of speech */
      pos: ShortSynsetType;
      sourceTargetHex: string;
      data: Definition;
    }[];
  };
  glossary: string;
}[];

declare module 'wordnet' {

  /**
   * Parses the database files and loads them into memory.
   *
   * @param {String} databaseDir Optional database directory path.
   * @return {Promise} Empty promise object.
   */
   export function init(databaseDir: string): Promise<undefined>;

  /**
   * Lists all the words.
   *
   * @return {Array<String>} List of all words.
   */
  export function list(): string[];

  /**
   * Looks up a word
   *
   * @param {String} word Word to look up.
   * @param {Boolean} skipPointers Whether to skip inclusion of pointer data.
   * @return {Promise<Definition>} Resolves with definitions for the given word.
   */
  export function lookup(word: string, skipPointers?: boolean): Promise<Definition>;
}

@JeffMII
Copy link

JeffMII commented Feb 11, 2022

@joelyjoel Hope you don't mind. I decided to fork the project and add the type declarations to submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants