travel

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: BSD-3-Clause Imports: 8 Imported by: 1

README

go-whosonfirst-travel

Go package for traveling Who's On First documents and their relations

Documentation

Go Reference

Tools

$> make cli
go build -mod vendor -o bin/wof-travel-id cmd/wof-travel-id/main.go
go build -mod vendor -o bin/wof-belongs-to cmd/wof-belongs-to/main.go
wof-travel-id
$> ./bin/wof-travel-id -h
Usage of ./bin/wof-travel-id:
  -csv
    	Emit results formatted as a comma-separated values.
  -hierarchies
    	Travel the hierarchies for each ID specified.
  -ids
    	Emit results as a line-separated list of IDs (traveled).
  -markdown
    	Emit results formatted as Markdown.
  -parent
    	Travel the parent ID of each ID specified.
  -singleton
    	... (default true)
  -source value
    	One or more valid whosonfirst/go-reader URIs to use to read WOF ID data, which may or may not be part of the sources to graph. This is work in progress.
  -stdin
    	Read IDs to travel from STDIN
  -superseded-by
    	Travel records that supersede each ID specified.
  -supersedes
    	Travel records that are superseded by each ID specified.
  -timings
    	Display timing information

For example:

$> ./bin/wof-travel-id \
	-source fs:///usr/local/data/whosonfirst-data-venue-us-ca/data \
	-supersedes 890535433
	
2018/08/07 17:26:46 890535433 Rock Bar (2012 - uuuu)
2018/08/07 17:26:46 1108808495 International Club (2001 - 2011)
2018/08/07 17:26:46 1108808497 Esperanza's (1996 - 2000)
2018/08/07 17:26:46 1108808499 Nello's Place (1981 - 1991)
2018/08/07 17:26:46 1108808501 Tiffany's Lodge (1975 - 1980)
2018/08/07 17:26:46 1108808503 Joe & Grill (1968 - 1974)
2018/08/07 17:26:46 1108808507 Walt's Place (1955 - 1965)
2018/08/07 17:26:46 1108808509 Geo & Walt's Place (1953 - 1954)
2018/08/07 17:26:46 1108808511 Welsh's Place (1951 - 1953)
2018/08/07 17:26:46 1108808513 Tiffany Club (1942 - 1950)
2018/08/07 17:26:46 1108808515 Cornelius Sweeney (1937 - uuuu)
2018/08/07 17:26:46 1108808517 Tiffany Inn (1934 - 1936)
2018/08/07 17:26:46 1108808519 Martin Burke (proprietor) (1931 - uuuu)
2018/08/07 17:26:46 1108808521 M. J. Reynolds (proprietor) (1922 - uuuu)
2018/08/07 17:26:46 1108808525 Timothy J. Costello (proprietor) (1915 - 1917)
2018/08/07 17:26:46 1108808527 Michael Coody (proprietor) (1911 - 1915)
2018/08/07 17:26:46 1108808529 Mary Caulfield (proprietor) (1910 - 1910)
2018/08/07 17:26:46 1108808531 Frank P. Caulfield (proprietor) (1902 - 1909)

Or:

$> ./bin/wof-travel-id \
	-source fs:///usr/local/data/whosonfirst-data-venue-us-ca/data \
	-superseded-by 1108808531
	
2018/08/07 17:30:55 1108808531 Frank P. Caulfield (proprietor) (1902 - 1909)
2018/08/07 17:30:55 1108808529 Mary Caulfield (proprietor) (1910 - 1910)
2018/08/07 17:30:55 1108808527 Michael Coody (proprietor) (1911 - 1915)
2018/08/07 17:30:55 1108808525 Timothy J. Costello (proprietor) (1915 - 1917)
2018/08/07 17:30:55 1108808521 M. J. Reynolds (proprietor) (1922 - uuuu)
2018/08/07 17:30:55 1108808519 Martin Burke (proprietor) (1931 - uuuu)
2018/08/07 17:30:55 1108808517 Tiffany Inn (1934 - 1936)
2018/08/07 17:30:55 1108808515 Cornelius Sweeney (1937 - uuuu)
2018/08/07 17:30:55 1108808513 Tiffany Club (1942 - 1950)
2018/08/07 17:30:55 1108808511 Welsh's Place (1951 - 1953)
2018/08/07 17:30:55 1108808509 Geo & Walt's Place (1953 - 1954)
2018/08/07 17:30:55 1108808507 Walt's Place (1955 - 1965)
2018/08/07 17:30:55 1108808503 Joe & Grill (1968 - 1974)
2018/08/07 17:30:55 1108808501 Tiffany's Lodge (1975 - 1980)
2018/08/07 17:30:55 1108808499 Nello's Place (1981 - 1991)
2018/08/07 17:30:55 1108808497 Esperanza's (1996 - 2000)
2018/08/07 17:30:55 1108808495 International Club (2001 - 2011)
2018/08/07 17:30:55 890535433 Rock Bar (2012 - uuuu)

Or:

$> ./bin/wof-travel-id \
	-source fs:///usr/local/data/whosonfirst-data-venue-us-ca/data \
	-source fs:///usr/local/data/whosonfirst-data/data \
	-supersedes \
	-parent 890535433
	
2018/08/07 17:28:00 890535433 Rock Bar (2012 - uuuu)
2018/08/07 17:28:00 1108808495 International Club (2001 - 2011)
2018/08/07 17:28:00 1108808497 Esperanza's (1996 - 2000)
2018/08/07 17:28:00 102112179 La Lengua (2008-11-19 - uuuu)
2018/08/07 17:28:00 1108808499 Nello's Place (1981 - 1991)
2018/08/07 17:28:00 1108808501 Tiffany's Lodge (1975 - 1980)
2018/08/07 17:28:00 1108808503 Joe & Grill (1968 - 1974)
2018/08/07 17:28:00 1108808507 Walt's Place (1955 - 1965)
2018/08/07 17:28:00 1108808509 Geo & Walt's Place (1953 - 1954)
2018/08/07 17:28:00 1108808511 Welsh's Place (1951 - 1953)
2018/08/07 17:28:00 1108808513 Tiffany Club (1942 - 1950)
2018/08/07 17:28:00 1108808515 Cornelius Sweeney (1937 - uuuu)
2018/08/07 17:28:00 1108808517 Tiffany Inn (1934 - 1936)
2018/08/07 17:28:00 1108808519 Martin Burke (proprietor) (1931 - uuuu)
2018/08/07 17:28:00 1108808521 M. J. Reynolds (proprietor) (1922 - uuuu)
2018/08/07 17:28:00 1108808525 Timothy J. Costello (proprietor) (1915 - 1917)
2018/08/07 17:28:00 1108808527 Michael Coody (proprietor) (1911 - 1915)
2018/08/07 17:28:00 1108808529 Mary Caulfield (proprietor) (1910 - 1910)
2018/08/07 17:28:00 1108808531 Frank P. Caulfield (proprietor) (1902 - 1909)
2018/08/07 17:28:00 85887469 Transmission (uuuu - uuuu)
2018/08/07 17:28:00 85922583 San Francisco (1850-04-15 - uuuu)
2018/08/07 17:28:00 85922583 San Francisco (1850-04-15 - uuuu)
2018/08/07 17:28:00 1125285611 City of San Francisco (uuuu - uuuu)
2018/08/07 17:28:00 102087579 San Francisco County
2018/08/07 17:28:00 102087579 San Francisco County
2018/08/07 17:28:00 85688637 California (uuuu - uuuu)
2018/08/07 17:28:01 85633793 United States (uuuu - uuuu)
2018/08/07 17:28:01 102191575 North America (uuuu - uuuu)

Note: There is still a condition where the same record can be processed twice (unless you explicitly enable this with the -singleton=true flag)

See also

Documentation

Overview

Package travel provides methods for iterating through one or more Who's On First records and "traveling" through the other records that it has a relationship with. These include parent records, records that supersede or are superseded by a WOF record or all the pointers in a records hierarchy.

Each step (or record) in a travel function is processed by a user-defined `TravelFunc`. This package includes a default callback function that simply prints some basic information about each record. More complex applications are outside the scope of this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TravelFunc

type TravelFunc func(context.Context, []byte, int64) error

TravelFunc is a callback function to be invoked for each `geojson.Feature` encountered during a travel session.

func DefaultTravelFunc

func DefaultTravelFunc() (TravelFunc, error)

DefaultTravelFunc returns a TravelFunc callback function that prints the current step, the feature's ID and name as well as its inception and cessation dates.

type TravelOptions

type TravelOptions struct {
	// TravelFunc is a callback function to be invoked for each `geojson.Feature` encountered during a travel session.
	Callback TravelFunc
	// A `reader.Reader` instance used to load GeoJSON Feature data.
	Reader reader.Reader
	// A boolean flag to indicate whether to record timing information.
	Timings bool
	// A boolean flag to indcate whether or not the same record should be traveled more than once. If true then records will only be traveled once.
	Singleton bool
	// A boolean flag to indicate whether a travel session should include the records that a feature supersedes .
	Supersedes bool
	// A boolean flag to indicate whether a travel session should include the records that a feature is superseded by .
	SupersededBy bool
	// A boolean flag to indicate whether a travel session should include a feature's parent record.
	ParentID bool
	// A boolean flag to indicate whether a travel session should include the record in a feature's hierarchy.
	Hierarchy bool
}

TravelOptions is a struct containing configuration details for a travel session.

func DefaultTravelOptions

func DefaultTravelOptions() (*TravelOptions, error)

DefaultTravelOptions returns a TravelOptions struct configured as a singleton and to use the DefaultTravelFunc callback, a `null://` reader.

type Traveler

type Traveler struct {
	// Options is a TravelOptions struct containing configuration details for the travel session.
	Options *TravelOptions

	Step int64
	// contains filtered or unexported fields
}

Traveler is a struct for walking the tree of supersedes or superseded_by relations for a Who's On First record.

func NewTraveler

func NewTraveler(opts *TravelOptions) (*Traveler, error)

Create a new Traveler instance.

func (*Traveler) TravelFeature

func (t *Traveler) TravelFeature(ctx context.Context, f []byte) error

Travel the relationships for 'f' (a GeoJSON feature).

func (*Traveler) TravelID

func (t *Traveler) TravelID(ctx context.Context, id int64) error

Travel the relationships for a Who's On First ID. The ID must be able to be read by the Traveler's `reader.Reader` instance defined in the `TravelOptions`.

Directories

Path Synopsis
cmd
Package cmd provides command line tools for traveling iterating through one or more Who's On First records and "traveling" through the other records that it has a relationship with
Package cmd provides command line tools for traveling iterating through one or more Who's On First records and "traveling" through the other records that it has a relationship with
Package traveller defines task-specific traveler methods.
Package traveller defines task-specific traveler methods.

Jump to

Keyboard shortcuts

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