placetypes

package module
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2024 License: BSD-3-Clause Imports: 17 Imported by: 30

README

go-whosonfirst-placetypes

Go package for working with Who's On First placetypes.

Documentation

Go Reference

Documentation is incomplete at this time.

Example

Simple
import (
       "log"

       "github.com/whosonfirst/go-whosonfirst-placetypes"
)

log.Println(placetypes.IsValidPlacetype("county"))
log.Println(placetypes.IsValidPlacetype("microhood"))
log.Println(placetypes.IsValidPlacetype("accelerator"))

id := int64(102312307)
log.Println(placetypes.IsValidPlacetypeId(id))          

Yields:

true
true
false
true

Tools

$> make cli
go build -mod vendor -o bin/wof-placetype-ancestors cmd/wof-placetype-ancestors/main.go
go build -mod vendor -o bin/wof-placetype-children cmd/wof-placetype-children/main.go
go build -mod vendor -o bin/wof-placetype-descendants cmd/wof-placetype-descendants/main.go
go build -mod vendor -o bin/wof-valid-placetype cmd/wof-valid-placetype/main.go
wof-placetype-ancestors
./bin/wof-placetype-ancestors -role common -role common_optional -role optional locality
2018/08/23 17:09:53 0 localadmin
2018/08/23 17:09:53 1 county
2018/08/23 17:09:53 2 macrocounty
2018/08/23 17:09:53 3 region
2018/08/23 17:09:53 4 macroregion
2018/08/23 17:09:53 5 dependency
2018/08/23 17:09:53 6 empire
2018/08/23 17:09:53 7 country
2018/08/23 17:09:53 8 continent
2018/08/23 17:09:53 9 disputed
2018/08/23 17:09:53 10 planet

./bin/wof-placetype-ancestors -role common -role common_optional -role optional enclosure
2018/08/23 17:10:42 0 venue
2018/08/23 17:10:42 1 arcade
2018/08/23 17:10:42 2 concourse
2018/08/23 17:10:42 3 wing
2018/08/23 17:10:42 4 building
2018/08/23 17:10:42 5 address
2018/08/23 17:10:42 6 intersection
2018/08/23 17:10:42 7 campus
2018/08/23 17:10:42 8 microhood
2018/08/23 17:10:42 9 neighbourhood
2018/08/23 17:10:42 10 macrohood
2018/08/23 17:10:42 11 borough
2018/08/23 17:10:42 12 locality
2018/08/23 17:10:42 13 localadmin
2018/08/23 17:10:42 14 county
2018/08/23 17:10:42 15 macrocounty
2018/08/23 17:10:42 16 region
2018/08/23 17:10:42 17 macroregion
2018/08/23 17:10:42 18 dependency
2018/08/23 17:10:42 19 empire
2018/08/23 17:10:42 20 country
2018/08/23 17:10:42 21 continent
2018/08/23 17:10:42 22 disputed
2018/08/23 17:10:42 23 planet
wof-placetype-children
./bin/wof-placetype-children locality
2018/08/24 18:16:53 0 borough
2018/08/24 18:16:53 1 postalcode
2018/08/24 18:16:53 2 macrohood
2018/08/24 18:16:53 3 neighbourhood
2018/08/24 18:16:53 4 campus
wof-placetype-descendants
./bin/wof-placetype-descendants -role common -role common_optional -role optional country
2018/08/24 18:15:49 0 marinearea
2018/08/24 18:15:49 1 timezone
2018/08/24 18:15:49 2 disputed
2018/08/24 18:15:49 3 macroregion
2018/08/24 18:15:49 4 region
2018/08/24 18:15:49 5 macrocounty
2018/08/24 18:15:49 6 county
2018/08/24 18:15:49 7 localadmin
2018/08/24 18:15:49 8 locality
2018/08/24 18:15:49 9 postalcode
2018/08/24 18:15:49 10 campus
2018/08/24 18:15:49 11 borough
2018/08/24 18:15:49 12 macrohood
2018/08/24 18:15:49 13 neighbourhood
2018/08/24 18:15:49 14 microhood
2018/08/24 18:15:49 15 intersection
2018/08/24 18:15:49 16 address
2018/08/24 18:15:49 17 building
2018/08/24 18:15:49 18 venue
2018/08/24 18:15:49 19 wing
2018/08/24 18:15:49 20 concourse
2018/08/24 18:15:49 21 arcade
2018/08/24 18:15:49 22 installation
2018/08/24 18:15:49 23 enclosure
wof-valid-placetype
$> ./bin/wof-valid-placetype bob custom building locality
2021/02/19 17:35:05 bob	false
2021/02/19 17:35:05 custom	true
2021/02/19 17:35:05 building	true
2021/02/19 17:35:05 locality	true

See also

Documentation

Index

Constants

View Source
const COMMON_COLOUR string = "blue"

COMMON_COLOUR defines the Graphviz edge colour for the "common" placetype role.

View Source
const COMMON_OPTIONAL_COLOUR string = "green"

COMMON_OPTIONAL_COLOUR defines the Graphviz edge colour for the "common_optional" placetype role.

View Source
const COMMON_OPTIONAL_ROLE string = "common_optional"

COMMON_OPTIONAL_ROLE defines the string label for the "common_optional" placetype role.

View Source
const COMMON_ROLE string = "common"

COMMON_ROLE defines the string label for the "common" placetype role.

View Source
const CUSTOM_COLOUR string = "black"

CUSTOM_COLOUR defines the Graphviz edge colour for the "custom" placetype role.

View Source
const CUSTOM_ROLE string = "custom"

CUSTOM_ROLE defines the string label for the "custom" placetype role.

View Source
const OPTIONAL_COLOUR string = "orange"

OPTIONAL_COLOUR defines the Graphviz edge colour for the "optional" placetype role.

View Source
const OPTIONAL_ROLE string = "optional"

OPTIONAL_ROLE defines the string label for the "optional" placetype role.

View Source
const WHOSONFIRST_DEFINITION_SCHEME string = "whosonfirst"

Variables

Functions

func AllRoles added in v0.6.0

func AllRoles() []string

AllRoles returns a list of all the known placetype roles.

func AppendPlacetype added in v0.2.0

func AppendPlacetype(pt WOFPlacetype) error

AppendPlacetype appends 'pt' to the catalog of available placetypes.

func AppendPlacetypeSpecification added in v0.2.2

func AppendPlacetypeSpecification(spec *WOFPlacetypeSpecification) error

AppendPlacetypeSpecification appends the placetypes defined in 'other_spec' to the catalog of available placetypes in 'spec'.

func IsAncestor added in v0.4.0

func IsAncestor(a *WOFPlacetype, b *WOFPlacetype) bool

Returns true is 'b' is an ancestor of 'a'.

func IsDescendant added in v0.4.0

func IsDescendant(a *WOFPlacetype, b *WOFPlacetype) bool

Returns true is 'b' is a descendant of 'a'.

func IsValidPlacetype

func IsValidPlacetype(name string) bool

IsValidPlacetypeId returns a boolean value indicating whether 'name' is a known and valid placetype name.

func IsValidPlacetypeId

func IsValidPlacetypeId(id int64) bool

IsValidPlacetypeId returns a boolean value indicating whether 'id' is a known and valid placetype ID.

func RegisterDefinition added in v0.7.0

func RegisterDefinition(ctx context.Context, scheme string, init_func DefinitionInitializationFunc) error

RegisterDefinition registers 'scheme' as a key pointing to 'init_func' in an internal lookup table used to create new `Definition` instances by the `NewDefinition` method.

func Schemes added in v0.7.0

func Schemes() []string

Schemes returns the list of schemes that have been registered.

Types

type Definition added in v0.7.0

type Definition interface {
	// Specification returns the `WOFPlacetypeSpecification` instance associated with the definition
	Specification() *WOFPlacetypeSpecification
	// Property return the relative (base) property name whose values (placetypes) are associated with the definition's placetype specification
	Property() string
	// URI() returns the URI used to create the definition
	URI() string
}

type Definition provides an interface for working with "core" and custom placetype specifications and for creating them using a URI-based syntax

func NewDefinition added in v0.7.0

func NewDefinition(ctx context.Context, uri string) (Definition, error)

NewDefinition returns a new `Definition` instance configured by 'uri'. The value of 'uri' is parsed as a `url.URL` and its scheme is used as the key for a corresponding `DefinitionInitializationFunc` function used to instantiate the new `Definition`. It is assumed that the scheme (and initialization function) have been registered by the `RegisterDefinition` method.

func NewWhosOnFirstDefinition added in v0.7.0

func NewWhosOnFirstDefinition(ctx context.Context, uri string) (Definition, error)

type DefinitionInitializationFunc added in v0.7.0

type DefinitionInitializationFunc func(ctx context.Context, uri string) (Definition, error)

DefinitionInitializationFunc is a function defined by individual definition package and used to create an instance of that definition

type WOFPlacetype

type WOFPlacetype struct {
	Id     int64   `json:"id"`
	Name   string  `json:"name"`
	Role   string  `json:"role"`
	Parent []int64 `json:"parent"`
}

Type WOFPlacetype defines an individual placetype encoded in a `WOFPlacetypeSpecification` instance. The choice of naming this "WOFPlacetype" is unfortunate because since it is easily confused with the actual JSON definition files for placetypes. However, we're stuck with it for now in order to preserve backwards compatibility. Womp womp...

This needs to be renamed to "Placetype" or something either at a /v1 or a v2 release. Either way it will be a breaking change. Doing it v2 (even if there is no explicit v1 release) might be "cleaner"...

func Ancestors

func Ancestors(pt *WOFPlacetype) []*WOFPlacetype

Ancestors returns the ancestors of role "common" for 'pt'.

func AncestorsForRoles

func AncestorsForRoles(pt *WOFPlacetype, roles []string) []*WOFPlacetype

AncestorsForRoles returns the ancestors matching any role in 'roles' for 'pt'.

func Children

func Children(pt *WOFPlacetype) []*WOFPlacetype

Children returns the immediate child placetype of 'pt'.

func Descendants

func Descendants(pt *WOFPlacetype) []*WOFPlacetype

Descendants returns the descendants of role "common" for 'pt'.

func DescendantsForRoles

func DescendantsForRoles(pt *WOFPlacetype, roles []string) []*WOFPlacetype

DescendantsForRoles returns the descendants matching any role in 'roles' for 'pt'.

func GetPlacetypeById

func GetPlacetypeById(id int64) (*WOFPlacetype, error)

GetPlacetypesByName returns the `WOFPlacetype` instance associated with 'id'.

func GetPlacetypeByName

func GetPlacetypeByName(name string) (*WOFPlacetype, error)

GetPlacetypesByName returns the `WOFPlacetype` instance associated with 'name'.

func Placetypes added in v0.1.1

func Placetypes() ([]*WOFPlacetype, error)

Placetypes returns all the known placetypes which are descendants of "planet" for the 'common', 'optional', 'common_optional', and 'custom' roles.

func PlacetypesForRoles added in v0.1.2

func PlacetypesForRoles(roles []string) ([]*WOFPlacetype, error)

Placetypes returns all the known placetypes which are descendants of "planet" whose role match any of those defined in 'roles'.

func (*WOFPlacetype) IsCorePlacetype added in v0.6.0

func (pt *WOFPlacetype) IsCorePlacetype() bool

IsCorePlacetype returns a boolean value if 'pt' is one of the "core" Who's On First placetypes.

func (*WOFPlacetype) String added in v0.6.0

func (pt *WOFPlacetype) String() string

String returns the value of the `Name` property for 'pt'.

type WOFPlacetypeAltNames

type WOFPlacetypeAltNames map[string][]string

type WOFPlacetypeName

type WOFPlacetypeName struct {
	// Lang is the RFC 5646 (BCP-47) language tag for the placetype name
	Lang string `json:"language"`
	Kind string `json:"kind"`
	// Name is the name of the placetype (in the language defined by `Lang`)
	Name string `json:"name"`
}

type WOFPlacetypeRecord added in v0.7.0

type WOFPlacetypeRecord struct {
	Id           int64             `json:"wof:id"`
	Name         string            `json:"wof:name"`
	Role         string            `json:"wof:role"`
	Parent       []string          `json:"wof:parent"`
	Concordances map[string]string `json:"wof:concordances"`
}

Type WOFPlacetypeRecord is a struct that maps to the JSON record files for individual placetypes in the `whosonfirst-placetypes` repo. Note that as of this writing it does not account for BCP-47 name: properties.

This needs to be renamed to "Record" either at a /v1 or a v2 release. Either way it will be a breaking change. Doing it v2 (even if there is no explicit v1 release) might be "cleaner"...

type WOFPlacetypeSpecification

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

This needs to be renamed to "Specification" either at a /v1 or a v2 release. Either way it will be a breaking change. Doing it v2 (even if there is no explicit v1 release) might be "cleaner"...

func DefaultWOFPlacetypeSpecification added in v0.2.1

func DefaultWOFPlacetypeSpecification() (*WOFPlacetypeSpecification, error)

func NewWOFPlacetypeSpecification added in v0.2.1

func NewWOFPlacetypeSpecification(body []byte) (*WOFPlacetypeSpecification, error)

NewWOFPlacetypeSpecification returns a `WOFPlacetypeSpecification` derived from 'body'.

func NewWOFPlacetypeSpecificationWithReader added in v0.2.3

func NewWOFPlacetypeSpecificationWithReader(r io.Reader) (*WOFPlacetypeSpecification, error)

func (*WOFPlacetypeSpecification) Ancestors added in v0.6.0

func (spec *WOFPlacetypeSpecification) Ancestors(pt *WOFPlacetype) []*WOFPlacetype

Ancestors returns the ancestors of role "common" for 'pt'.

func (*WOFPlacetypeSpecification) AncestorsForRoles added in v0.6.0

func (spec *WOFPlacetypeSpecification) AncestorsForRoles(pt *WOFPlacetype, roles []string) []*WOFPlacetype

AncestorsForRoles returns the ancestors matching any role in 'roles' for 'pt'.

func (*WOFPlacetypeSpecification) AppendPlacetype added in v0.2.0

func (spec *WOFPlacetypeSpecification) AppendPlacetype(pt WOFPlacetype) error

AppendPlacetype appends 'pt' to the catalog of available placetypes.

func (*WOFPlacetypeSpecification) AppendPlacetypeSpecification added in v0.2.2

func (spec *WOFPlacetypeSpecification) AppendPlacetypeSpecification(other_spec *WOFPlacetypeSpecification) error

AppendPlacetypeSpecification appends the placetypes defined in 'other_spec' to the catalog of available placetypes in 'spec'.

func (*WOFPlacetypeSpecification) Catalog added in v0.2.0

func (spec *WOFPlacetypeSpecification) Catalog() map[string]WOFPlacetype

Catalog returns the catalog of placetypes contained by 'spec'.

func (*WOFPlacetypeSpecification) Children added in v0.6.0

func (spec *WOFPlacetypeSpecification) Children(pt *WOFPlacetype) []*WOFPlacetype

Children returns the immediate child placetype of 'pt'.

func (*WOFPlacetypeSpecification) Descendants added in v0.6.0

func (spec *WOFPlacetypeSpecification) Descendants(pt *WOFPlacetype) []*WOFPlacetype

Descendants returns the descendants of role "common" for 'pt'.

func (*WOFPlacetypeSpecification) DescendantsForRoles added in v0.6.0

func (spec *WOFPlacetypeSpecification) DescendantsForRoles(pt *WOFPlacetype, roles []string) []*WOFPlacetype

DescendantsForRoles returns the descendants matching any role in 'roles' for 'pt'.

func (*WOFPlacetypeSpecification) GetPlacetypeById added in v0.2.0

func (spec *WOFPlacetypeSpecification) GetPlacetypeById(id int64) (*WOFPlacetype, error)

GetPlacetypesByName returns the `WOFPlacetype` instance associated with 'id'.

func (*WOFPlacetypeSpecification) GetPlacetypeByName added in v0.2.0

func (spec *WOFPlacetypeSpecification) GetPlacetypeByName(name string) (*WOFPlacetype, error)

GetPlacetypesByName returns the `WOFPlacetype` instance associated with 'name'.

func (*WOFPlacetypeSpecification) GraphPlacetypes added in v0.6.0

func (spec *WOFPlacetypeSpecification) GraphPlacetypes() (graph.Graph[string, *WOFPlacetype], error)

GraphPlacetypes will generate a directed graph for all the placetypes defined in 'spec'.

func (*WOFPlacetypeSpecification) IsAncestor added in v0.6.0

func (spec *WOFPlacetypeSpecification) IsAncestor(a *WOFPlacetype, b *WOFPlacetype) bool

Returns true is 'b' is an ancestor of 'a'.

func (*WOFPlacetypeSpecification) IsDescendant added in v0.6.0

func (spec *WOFPlacetypeSpecification) IsDescendant(a *WOFPlacetype, b *WOFPlacetype) bool

Returns true is 'b' is a descendant of 'a'.

func (*WOFPlacetypeSpecification) IsValidPlacetype added in v0.6.0

func (spec *WOFPlacetypeSpecification) IsValidPlacetype(name string) bool

IsValidPlacetypeId returns a boolean value indicating whether 'name' is a known and valid placetype name.

func (*WOFPlacetypeSpecification) IsValidPlacetypeId added in v0.6.0

func (spec *WOFPlacetypeSpecification) IsValidPlacetypeId(id int64) bool

IsValidPlacetypeId returns a boolean value indicating whether 'id' is a known and valid placetype ID.

func (*WOFPlacetypeSpecification) Placetypes added in v0.6.0

func (spec *WOFPlacetypeSpecification) Placetypes() ([]*WOFPlacetype, error)

Placetypes returns all the known placetypes which are descendants of "planet" for the 'common', 'optional', 'common_optional', and 'custom' roles.

func (*WOFPlacetypeSpecification) PlacetypesForRoles added in v0.6.0

func (spec *WOFPlacetypeSpecification) PlacetypesForRoles(roles []string) ([]*WOFPlacetype, error)

Placetypes returns all the known placetypes which are descendants of "planet" whose role match any of those defined in 'roles'.

func (*WOFPlacetypeSpecification) PlacetypesToGraphviz added in v0.6.0

func (spec *WOFPlacetypeSpecification) PlacetypesToGraphviz(wr io.Writer) error

PlacetypesToGraphviz will generate a DOT description for 'spec' and write it to 'wr'.

type WhosOnFirstDefinition added in v0.7.0

type WhosOnFirstDefinition struct {
	Definition
	// contains filtered or unexported fields
}

func (*WhosOnFirstDefinition) Property added in v0.7.0

func (s *WhosOnFirstDefinition) Property() string

func (*WhosOnFirstDefinition) Specification added in v0.7.0

func (*WhosOnFirstDefinition) URI added in v0.7.0

func (s *WhosOnFirstDefinition) URI() string

Directories

Path Synopsis
cmd
Package draw provides methods for graphical representations of a placetypes specification
Package draw provides methods for graphical representations of a placetypes specification

Jump to

Keyboard shortcuts

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