github.com/fluhus/gostuff@v0.4.1-0.20240331134726-be71864f2b5d/nlp/wordnet/string.go (about)

     1  package wordnet
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  )
     7  
     8  // String functions for types.
     9  
    10  // TODO(amit): Consider removing String() functions to simplify the API.
    11  
    12  // Returns a compact string representation of the WordNet data collection, for
    13  // debugging.
    14  func (wn *WordNet) String() string {
    15  	return fmt.Sprintf("WordNet[%d lemmas, %d synsets, %d exceptions,"+
    16  		" %d examples]",
    17  		len(wn.Lemma), len(wn.Synset), len(wn.Exception), len(wn.Example))
    18  }
    19  
    20  // Returns a string representation of the synset, for debugging.
    21  func (s *Synset) String() string {
    22  	result := bytes.NewBuffer(make([]byte, 0, 100))
    23  	fmt.Fprintf(result, "Synset[%s.", s.Pos)
    24  	for i, word := range s.Word {
    25  		if i > 0 {
    26  			fmt.Fprintf(result, ",")
    27  		}
    28  		fmt.Fprintf(result, " %v", word)
    29  	}
    30  	fmt.Fprintf(result, ": %s]", s.Gloss)
    31  	return result.String()
    32  }