-
Notifications
You must be signed in to change notification settings - Fork 9
/
format.rb
99 lines (95 loc) · 3.41 KB
/
format.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
module RDF::N3
##
# RDFa format specification.
#
# @example Obtaining an Notation3 format class
# RDF::Format.for(:n3) #=> RDF::N3::Format
# RDF::Format.for("etc/foaf.n3")
# RDF::Format.for(file_name: "etc/foaf.n3")
# RDF::Format.for(file_extension: "n3")
# RDF::Format.for(content_type: "text/n3")
#
# @example Obtaining serialization format MIME types
# RDF::Format.content_types #=> {"text/n3")" => [RDF::N3::Format]}
#
# @example Obtaining serialization format file extension mappings
# RDF::Format.file_extensions #=> {n3: "text/n3"}
#
# @see https://www.w3.org/TR/rdf-testcases/#ntriples
class Format < RDF::Format
content_type 'text/n3',
extension: :n3,
aliases: %w(text/rdf+n3;q=0.2 application/rdf+n3;q=0.2),
uri: 'http://www.w3.org/ns/formats/N3'
content_encoding 'utf-8'
reader { RDF::N3::Reader }
writer { RDF::N3::Writer }
# Symbols which may be used to lookup this format
def self.symbols
[:n3, :notation3]
end
##
# Hash of CLI commands appropriate for this format
# @return [Hash{Symbol => Hash}]
def self.cli_commands
{
reason: {
description: "Reason over formulae.",
help: "reason [--think] file\nPerform Notation-3 reasoning.",
parse: false,
# Only shows when input and output format set
filter: {format: :n3},
repository: RDF::N3::Repository.new,
lambda: ->(argv, **options) do
repository = options[:repository]
result_repo = RDF::N3::Repository.new
RDF::CLI.parse(argv, format: :n3, list_terms: true, **options) do |reader|
reasoner = RDF::N3::Reasoner.new(reader, **options)
reasoner.reason!(**options)
if options[:conclusions]
result_repo << reasoner.conclusions
elsif options[:data]
result_repo << reasoner.data
else
result_repo << reasoner
end
end
# Replace input repository with results
repository.clear!
repository << result_repo
end,
options: [
RDF::CLI::Option.new(
symbol: :conclusions,
datatype: TrueClass,
control: :checkbox,
use: :optional,
on: ["--conclusions"],
description: "Exclude formulae and statements in the original dataset."),
RDF::CLI::Option.new(
symbol: :data,
datatype: TrueClass,
control: :checkbox,
use: :optional,
on: ["--data"],
description: "Only results from default graph, excluding formulae or variables."),
RDF::CLI::Option.new(
symbol: :strings,
datatype: TrueClass,
control: :checkbox,
use: :optional,
on: ["--strings"],
description: "Returns the concatenated strings from log:outputString."),
RDF::CLI::Option.new(
symbol: :think,
datatype: TrueClass,
control: :checkbox,
use: :optional,
on: ["--think"],
description: "Continuously execute until results stop growing."),
]
},
}
end
end
end