models

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package models contains the code for the models used in the cmd CLI package. It also contains utility functions used by these models, search functionality, and the drug configuration file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(err error)

Check quickly handles the checking of errors and logs if the error is not nil.

Types

type Drug

type Drug struct {
	Name        string   `json:"name" yaml:"Name"`
	SearchTerms []string `json:"search_terms" yaml:"Search Terms"`
	Tags        []string `json:"tags" yaml:"Tags"`
}

Drug is the main data struct for parsing out each entry in the drugInfo yaml file.

func (*Drug) SearchText

func (d *Drug) SearchText(text string) TextSearchResult

SearchText takes a Drug and searches the specified text for any close matches. This uses the Jaro-Winkler distance (>= 0.90) to define a "close" match and distance == 1.0 for an "exact" match. SearchText returns a TextSearchResult instance.

func (*Drug) SearchTextStrict

func (d *Drug) SearchTextStrict(text string) TextSearchResult

SearchTextStrict does everything that SearchText does, but only looks for exact matches. Exact matches defined by Jaro-Winkler distance == 1.0. Returns a TextSearchResult instance.

type Drugs

type Drugs struct {
	Drugs []Drug `json:"drugs" yaml:"Drugs"`
}

Drugs puts an array of the Drug items into one struct for easy serialization.

func (Drugs) Load

func (Drugs) Load() Drugs

Load reads the drug data from file and marshals it into Drugs.

type MatchResult

type MatchResult struct {
	ExactMatch bool
	CloseMatch bool
}

MatchResult contains information regarding whether an Exact or Close match was found.

type MultipleResults

type MultipleResults struct {
	Data []Result `json:"data"`
}

MultipleResults holds many Result items in an array for easy serialization.

func (*MultipleResults) LoadFromFile added in v0.2.0

func (r *MultipleResults) LoadFromFile(path string)

LoadFromFile reads MultipleResults from the specified filepath.

func (MultipleResults) ToFile

func (r MultipleResults) ToFile(path string)

ToFile writes MultipleResults to the specified filepath.

type Result

type Result struct {
	RecordID        string   `json:"record_id"`
	DrugName        string   `json:"drug_name"`
	SimilarityRatio float64  `json:"similarity_ratio"`
	WordFound       string   `json:"word_found"`
	Tags            []string `json:"tags"`
	TempID          int      `json:"-"` // ignores
}

Result is the struct to manage the output of the program. This constitutes the RecordID, DrugName, SimilarityRatio, WordFound and Tags labels which are all assembled when running search.

func ScanDrugs

func ScanDrugs(texts []string, strict bool) []Result

ScanDrugs takes an array of text objects and scans each text instance for each potential Drug from the config file. Returns an array of Result objects.

type SearchResult

type SearchResult struct {
	Distance int // Jaro-Winkler distance
	Source   string
	Target   string
}

SearchResult contains information regarding the JaroWinkler Distance between the Source and the Target.

type TextSearchResult

type TextSearchResult struct {
	// contains filtered or unexported fields
}

TextSearchResult contains the specific results of search functionality and is used to create a full Result item.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL