Title: | Code-Logics to Handle Ontologies |
---|---|
Description: | Provides tools to build and work with an ontology of linked (open) data in a tidy workflow. It is inspired by the Food and Agrilculture Organizations (FAO) caliper platform <https://www.fao.org/statistics/caliper/web/> and makes use of the Simple Knowledge Organisation System (SKOS). |
Authors: | Steffen Ehrmann [aut, cre] |
Maintainer: | Steffen Ehrmann <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.7.4 |
Built: | 2025-02-16 06:02:44 UTC |
Source: | https://github.com/luckinet/ontologics |
Allows the user to match concepts with an already existing ontology, without actually writing into the ontology, but instead storing the resulting matching table as csv.
edit_matches( new, topLevel, source = NULL, ontology = NULL, matchDir = NULL, stringdist = TRUE, verbose = TRUE, beep = NULL )
edit_matches( new, topLevel, source = NULL, ontology = NULL, matchDir = NULL, stringdist = TRUE, verbose = TRUE, beep = NULL )
new |
|
topLevel |
|
source |
|
ontology |
|
matchDir |
|
stringdist |
|
verbose |
|
beep |
|
In order to match new concepts into an already existing ontology, it
may become necessary to carry out manual matches of the new concepts with
already harmonised concepts, for example, when the new concepts are
described with terms that are not yet in the ontology. This function puts
together a table, in which the user would edit matches by hand. Whith the
argument verbose = TRUE
, detailed information about the edit process
are shown to the user. After defining matches, and even if not all
necessary matches are finished, the function stores a specific "matching
table" with the name match_SOURCE.csv in the respective directory
(matchDir
), from where work can be picked up and continued at
another time.
Fuzzy matching is carried out and matches with 0, 1 or 2 differing charcters are presented in a respective column.
A table that contains all new matches, or if none of the new concepts weren't already in the ontology, a table of the already sucessful matches.
Export an ontology as RDF
export_as_rdf(ontology, filename)
export_as_rdf(ontology, filename)
ontology |
|
filename |
|
No return value, called for the side effect of exporting an ontology.
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) ## Not run: export_as_rdf(ontology = onto, filename = "onto.ttl") ## End(Not run)
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) ## Not run: export_as_rdf(ontology = onto, filename = "onto.ttl") ## End(Not run)
Get class(es) in an ontology
get_class(..., regex = FALSE, external = FALSE, ontology = NULL)
get_class(..., regex = FALSE, external = FALSE, ontology = NULL)
... |
combination of column name and value to filter that column by. The
value to filter by can be provided as regular expression, if |
regex |
|
external |
|
ontology |
|
A table of the class(es) in the ontology according to the values in
...
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) # exact classes from a loaded ontology ... get_class(label = "class", ontology = onto) # ... or one stored on the harddisc get_class(id = ".xx.xx", ontology = ontoDir) # use regular expressions ... get_class(label = "ro", regex = TRUE, ontology = onto) # get all sources get_class(ontology = onto)
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) # exact classes from a loaded ontology ... get_class(label = "class", ontology = onto) # ... or one stored on the harddisc get_class(id = ".xx.xx", ontology = ontoDir) # use regular expressions ... get_class(label = "ro", regex = TRUE, ontology = onto) # get all sources get_class(ontology = onto)
Get a concept in an ontology
get_concept(..., external = FALSE, matches = FALSE, ontology = NULL)
get_concept(..., external = FALSE, matches = FALSE, ontology = NULL)
... |
combination of column name and value to filter that column by. |
external |
|
matches |
|
ontology |
|
A table of a subset of the ontology according to the values in
...
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) # exact matches from a loaded ontology ... get_concept(label = "FODDER CROPS", ontology = onto) # ... or a path get_concept(label = c("FODDER CROPS", "CEREALS"), ontology = ontoDir) # ignore querries that would not be valid in filter() get_concept(label != 'Bioenergy woody' & has_broader == '.01', ontology = onto) # extract concepts based on regular expressions library(stringr) get_concept(str_detect(label, "crop") & str_detect(id, ".03$"), ontology = ontoDir)
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) # exact matches from a loaded ontology ... get_concept(label = "FODDER CROPS", ontology = onto) # ... or a path get_concept(label = c("FODDER CROPS", "CEREALS"), ontology = ontoDir) # ignore querries that would not be valid in filter() get_concept(label != 'Bioenergy woody' & has_broader == '.01', ontology = onto) # extract concepts based on regular expressions library(stringr) get_concept(str_detect(label, "crop") & str_detect(id, ".03$"), ontology = ontoDir)
Get source(e) in an ontology
get_source(..., regex = FALSE, ontology = NULL)
get_source(..., regex = FALSE, ontology = NULL)
... |
combination of column name and value to filter that column by. The
value to filter by can be provided as regular expression, if |
regex |
|
ontology |
|
A table of the source(s) in the ontology according to the values in
...
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) # exact sources from a loaded ontology ... get_source(label = "harmonised", ontology = onto) # ... or one stored on the harddisc get_source(version = "0.0.1", ontology = ontoDir) # get all sources get_source(ontology = onto)
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) # exact sources from a loaded ontology ... get_source(label = "harmonised", ontology = onto) # ... or one stored on the harddisc get_source(version = "0.0.1", ontology = ontoDir) # get all sources get_source(ontology = onto)
Load an ontology
load_ontology(path = NULL)
load_ontology(path = NULL)
path |
|
A table of the full ontology (i.e., where attribute and mapping tables are joined).
# load an already existing ontology load_ontology(path = system.file("extdata", "crops.rds", package = "ontologics"))
# load an already existing ontology load_ontology(path = system.file("extdata", "crops.rds", package = "ontologics"))
Make a tree of an ontology
make_tree(..., reverse = FALSE, ontology = NULL)
make_tree(..., reverse = FALSE, ontology = NULL)
... |
|
reverse |
|
ontology |
|
Add a new valid class to an ontology
new_class(new, target, description = NULL, ontology = NULL)
new_class(new, target, description = NULL, ontology = NULL)
new |
|
target |
|
description |
|
ontology |
|
the updated ontology that contains the new class(es) defined here.
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) onto <- new_class(new = "use type", target = "class", description = "something", ontology = onto)
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) onto <- new_class(new = "use type", target = "class", description = "something", ontology = onto)
This adds a new concept to an existing ontology to semantically integrate and thus harmonise it with the already existing ontology.
new_concept( new, broader = NULL, description = NULL, class = NULL, ontology = NULL )
new_concept( new, broader = NULL, description = NULL, class = NULL, ontology = NULL )
new |
|
broader |
|
description |
|
class |
|
ontology |
|
returns invisibly a table of the new harmonised concepts that were added to the ontology, or a message that nothing new was added.
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) # add fully known concepts concepts <- data.frame( old = c("Bioenergy woody", "Bioenergy herbaceous"), new = c("acacia", "miscanthus") ) onto <- new_source( version = "0.0.1", name = "externalDataset", description = "a vocabulary", homepage = "https://www.something.net", license = "CC-BY-0", ontology = onto ) onto <- new_concept( new = concepts$new, broader = get_concept(label = concepts$old, ontology = onto), class = "crop", ontology = onto ) # add concepts where the nesting is clear, but not the new class concepts <- data.frame( old = c("Barley", "Barley"), new = c("food", "bio-energy") ) onto <- new_concept( new = concepts$new, broader = get_concept(label = concepts$old, ontology = onto), ontology = onto ) # define that class ... onto <- new_class( new = "use type", target = "class", description = "the way a crop is used", ontology = onto ) # ... and set the concepts again onto <- new_concept( new = concepts$new, broader = get_concept(label = concepts$old, ontology = onto), class = "use type", ontology = onto )
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) # add fully known concepts concepts <- data.frame( old = c("Bioenergy woody", "Bioenergy herbaceous"), new = c("acacia", "miscanthus") ) onto <- new_source( version = "0.0.1", name = "externalDataset", description = "a vocabulary", homepage = "https://www.something.net", license = "CC-BY-0", ontology = onto ) onto <- new_concept( new = concepts$new, broader = get_concept(label = concepts$old, ontology = onto), class = "crop", ontology = onto ) # add concepts where the nesting is clear, but not the new class concepts <- data.frame( old = c("Barley", "Barley"), new = c("food", "bio-energy") ) onto <- new_concept( new = concepts$new, broader = get_concept(label = concepts$old, ontology = onto), ontology = onto ) # define that class ... onto <- new_class( new = "use type", target = "class", description = "the way a crop is used", ontology = onto ) # ... and set the concepts again onto <- new_concept( new = concepts$new, broader = get_concept(label = concepts$old, ontology = onto), class = "use type", ontology = onto )
Extend an ontology by creating mappings between classes and concepts of external vocabularies and the harmonised classes and concepts.
new_mapping( new = NULL, target, source = NULL, lut = NULL, match = NULL, certainty = NULL, type = "concept", ontology = NULL, verbose = FALSE, beep = NULL )
new_mapping( new = NULL, target, source = NULL, lut = NULL, match = NULL, certainty = NULL, type = "concept", ontology = NULL, verbose = FALSE, beep = NULL )
new |
|
target |
|
source |
|
lut |
|
match |
|
certainty |
. |
type |
|
ontology |
|
verbose |
|
beep |
|
No return value, called for the side effect of adding new mappings to an ontology.
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) mapping <- data.frame(old = c("BIOENERGY CROPS", "Bioenergy woody", "Other bioenergy crops"), new = c("bioenergy plants", "Wood plantation for fuel", "Algae for bioenergy"), type = c("close", "broader", "broader")) onto <- new_source(name = "externalDataset", version = "0.0.1", description = "a vocabulary", homepage = "https://www.something.net", license = "CC-BY-0", ontology = onto) onto <- get_concept(label = mapping$old, ontology = onto) %>% new_mapping(new = mapping$new, target = ., match = mapping$type, source = "externalDataset", certainty = 3, ontology = onto)
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) mapping <- data.frame(old = c("BIOENERGY CROPS", "Bioenergy woody", "Other bioenergy crops"), new = c("bioenergy plants", "Wood plantation for fuel", "Algae for bioenergy"), type = c("close", "broader", "broader")) onto <- new_source(name = "externalDataset", version = "0.0.1", description = "a vocabulary", homepage = "https://www.something.net", license = "CC-BY-0", ontology = onto) onto <- get_concept(label = mapping$old, ontology = onto) %>% new_mapping(new = mapping$new, target = ., match = mapping$type, source = "externalDataset", certainty = 3, ontology = onto)
Add a new valid source to an ontology
new_source( ontology = NULL, name = NULL, version = NULL, date = NULL, description = NULL, homepage = NULL, uri_prefix = NULL, license = NULL, notes = NULL )
new_source( ontology = NULL, name = NULL, version = NULL, date = NULL, description = NULL, homepage = NULL, uri_prefix = NULL, license = NULL, notes = NULL )
ontology |
|
name |
|
version |
|
date |
|
description |
|
homepage |
|
uri_prefix |
|
license |
|
notes |
|
Fundamentally, there are two types of sources that can be defined with this function.
attribute collections: where a collection of terms or concepts are associated as a descriptive attribute to the harmonised concepts, and
linked open data: where the concepts that occur in another vocabulary or ontology and which are themselves part of linked datasets (and hence have a valid URI) are associated as related concepts to the harmonised concepts.
In the latter case, each mapped concept should be provided by its ID and the source needs to have a URL that allows in combination with the concept IDs to construct the URI under which the mapped concepts are stored in the semantic web.
the updated ontology that contains the new source defined here.
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) onto <- new_source(name = "externalDataset", version = "0.0.1", description = "a vocabulary", homepage = "https://www.something.net", license = "CC-BY-0", ontology = onto)
ontoDir <- system.file("extdata", "crops.rds", package = "ontologics") onto <- load_ontology(path = ontoDir) onto <- new_source(name = "externalDataset", version = "0.0.1", description = "a vocabulary", homepage = "https://www.something.net", license = "CC-BY-0", ontology = onto)
Ontology class (S4) and methods
sources
classes
concepts
Print onto in the console
## S4 method for signature 'onto' show(object)
## S4 method for signature 'onto' show(object)
object |
object to |
Start an ontology
start_ontology( name = NULL, version = NULL, path = NULL, code = ".xx", description = NULL, homepage = NULL, uri_prefix = NULL, license = NULL, notes = NULL )
start_ontology( name = NULL, version = NULL, path = NULL, code = ".xx", description = NULL, homepage = NULL, uri_prefix = NULL, license = NULL, notes = NULL )
name |
|
version |
|
path |
|
code |
|
description |
|
homepage |
|
uri_prefix |
|
license |
|
notes |
|
it returns the new, empty ontology and also stores that within the
directory specified in path
.
start_ontology(name = "crops", path = tempdir())
start_ontology(name = "crops", path = tempdir())