2017-05-29 21:12:50 +00:00
|
|
|
defmodule RDF.Utils.ResourceClassifier do
|
2017-06-11 12:24:29 +00:00
|
|
|
@moduledoc false
|
2017-05-29 21:12:50 +00:00
|
|
|
|
|
|
|
alias RDF.Description
|
|
|
|
|
2020-04-10 21:40:33 +00:00
|
|
|
import RDF.Utils.Bootstrapping
|
|
|
|
|
|
|
|
@rdf_type rdf_iri("type")
|
2017-06-10 21:08:49 +00:00
|
|
|
|
2017-05-29 21:12:50 +00:00
|
|
|
@doc """
|
|
|
|
Determines if the given resource is RDF property by
|
|
|
|
"""
|
|
|
|
def property?(resource, data) do
|
2017-06-05 00:58:49 +00:00
|
|
|
with %Description{} = description <- RDF.Data.description(data, resource) do
|
2017-05-29 21:12:50 +00:00
|
|
|
property_by_domain?(description) or
|
2017-06-10 21:08:49 +00:00
|
|
|
property_by_rdf_type?(Description.get(description, @rdf_type))
|
2017-05-29 21:12:50 +00:00
|
|
|
end
|
|
|
|
# || property_by_predicate_usage?(resource, data)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2020-04-10 21:40:33 +00:00
|
|
|
@property_properties Enum.map(~w[
|
|
|
|
domain
|
|
|
|
range
|
|
|
|
subPropertyOf
|
|
|
|
], &rdfs_iri/1) ++
|
|
|
|
Enum.map(~w[
|
|
|
|
equivalentProperty
|
|
|
|
inverseOf
|
|
|
|
propertyDisjointWith
|
|
|
|
], &owl_iri/1)
|
2017-05-29 21:12:50 +00:00
|
|
|
|> MapSet.new
|
|
|
|
|
|
|
|
defp property_by_domain?(description) do
|
|
|
|
Enum.any? @property_properties, fn property ->
|
|
|
|
description[property]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-12 13:38:02 +00:00
|
|
|
@property_classes [
|
|
|
|
rdf_iri("Property"),
|
|
|
|
rdfs_iri("ContainerMembershipProperty")
|
|
|
|
|
|
|
|
|
Enum.map(~w[
|
|
|
|
ObjectProperty
|
|
|
|
DatatypeProperty
|
|
|
|
AnnotationProperty
|
|
|
|
FunctionalProperty
|
|
|
|
InverseFunctionalProperty
|
|
|
|
SymmetricProperty
|
|
|
|
AsymmetricProperty
|
|
|
|
ReflexiveProperty
|
|
|
|
IrreflexiveProperty
|
|
|
|
TransitiveProperty
|
|
|
|
DeprecatedProperty
|
|
|
|
], &owl_iri/1)
|
|
|
|
]
|
|
|
|
|> MapSet.new
|
2017-05-29 21:12:50 +00:00
|
|
|
|
2020-03-02 01:07:31 +00:00
|
|
|
@dialyzer {:nowarn_function, property_by_rdf_type?: 1}
|
2017-05-29 21:12:50 +00:00
|
|
|
defp property_by_rdf_type?(nil), do: nil
|
|
|
|
defp property_by_rdf_type?(types) do
|
|
|
|
not (
|
|
|
|
types
|
|
|
|
|> MapSet.new
|
|
|
|
|> MapSet.disjoint?(@property_classes)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# defp property_by_predicate_usage?(resource, data) do
|
|
|
|
# resource in Graph.predicates(data) || nil
|
|
|
|
# end
|
|
|
|
|
|
|
|
end
|