Help us shape the future of Go! Take the 2026 Go Developer Survey

gofp

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: MIT Imports: 6 Imported by: 0

README

Gofp Owl-Functional Parser

Gofp reads OWL2 files with functional syntax.

The resulting structures strictly resemble the OWL-Functional structures. For example, a SubClassOf axiom is parsed into an axioms.SubClassOf instance. Everything is read into memory at once.

The project structure and the package and type names depict the OWL documentation from here: https://www.w3.org/2007/OWL/refcard

The implementation idea comes from https://blog.gopheracademy.com/advent-2014/parsers-lexers/.

Example for parsing a file:

f, _ := os.Open("pizza-functional.owl")
if err != nil {
	panic(err)
}
defer f.Close()

o, err := gofp.OntologyFromReader(f, "source was pizza-functional.owl")
if err != nil {
	log.Fatal(gofp.ErrorMsgWithPosition(err))
}
log.Println("That's what we parsed:", o.About())

To run that example, cd into the gofp/example/pizza/ directory and type

go run main.go

How to access the parsed data ?

We get an owlfunctional.Ontology instance from the parser. By default, this has an Ontology.K attribute with all parsed knowledge, which is made up of OWL axioms and declarations. All parsed elements are accessible by the "All"-prefixed methods here, like AllSubClassOfs(). Additionally, all declarations are accessible by their IRI, for example ClassDecl("example.com/Pizza").

// Example: print all parsed class declaration IRIs:
for _, declaration := range o.K.AllClassDecls() {
	fmt.Println(declaration.IRI)
}

While this is the default, Gofp can parse directly into custom types, alternatively. See also the parameter documentation of the owlfunctional.NewOntology function.

Caveats

The implementation is not complete. The "import" statement is unknown and breaks parsing. Annotations and free text inside an Ontology element are unknown and break parsing. Some more statements and datatypes are unknown; most of these come from the "Individual" and "Annotation" categories. A management for IRI prefixes is missing. Further, all input must be UTF-8.

Recent API changes

Note that the API may continue to change. Gofp, by intention, has a v0.* version (see https://blog.golang.org/publishing-go-modules for golang versioning).

  • With commit 6e35dd from Oct 08 2019, the import path of "owlfunctional/declarations" was changed to "owlfunctional/decl", and "owlfunctional/ontologies" was shortened to "owlfunctional".
  • Since commit 018e1d from Apr 23 2019, the parsed elements are not found in Ontology.All* - slices and maps anymore. See above, "How to access the parsed data" for details. That API change was made to (optionally) parse directly into custom types.

Prerequisites

A Go compiler and the standard library.

Remarkable OWL parser projects, choosen arbitrarily

License

Gofp is MIT licensed.

Documentation

Overview

gofp is an Owl Functional Parser. gofp reads OWL-Functional input into Golang structures, for further processing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorMsgWithPosition

func ErrorMsgWithPosition(err error) string

ErrorMsgWithPosition produces a user message like "untempting topping on margherita pizza in: pizza.owl 18:32 after '...Pizza ObjectSomeValuesFrom(:hasTopping'" for errors or type parser.PErr. For other error types, err.Error() is returned.

func OntologyFromParser

func OntologyFromParser(p *parser.Parser, rc owlfunctional.StoreConfig) (ontology *owlfunctional.Ontology, err error)

OntologyFromReader uses the Parser p to create an Ontology struct. The configuration rc allows custom storage of Declarations and Axioms. As a usage example of OntologyFromParser, see the code of the OntologyFromReader function. Note that the API may change and Gofp, in its early state, does not use a semantic version number.

func OntologyFromReader

func OntologyFromReader(r io.Reader, sourceName string) (ontology *owlfunctional.Ontology, err error)

OntologyFromReader parses an owl-functional file contents into an Ontology struct. r is the OWL-Functional file contents. sourceName: see parser.NewParser() For less convenience but more control, see the OntologyFromParser function.

func ParserPositionMsg

func ParserPositionMsg(pos parser.ParserPosition) string

ParserPositionMsg returns a position desciption for the user , like "pizza.owl 18:32 after '...Pizza ObjectSomeValuesFrom(:hasTopping'"

Types

This section is empty.

Directories

Path Synopsis
example
mini command
pizza command
mock are functions and types for unit tests.
mock are functions and types for unit tests.
parser
parser takes the concept from: https://blog.gopheracademy.com/advent-2014/parsers-lexers/
parser takes the concept from: https://blog.gopheracademy.com/advent-2014/parsers-lexers/
tech are types not required by OWL but internally.
tech are types not required by OWL but internally.

Jump to

Keyboard shortcuts

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