rdf-turtle 3.0.2 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rdf/turtle/writer.rb +40 -46
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 499e06e63d69ec0216db2600e34260d5eda5c7a3736e8f1a42c63a91c716779c
|
4
|
+
data.tar.gz: 3443fdb3e53d2b12d66f6a9534a9532dabde58b0b319ecc62ffff0a4bd87afb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cad03d53fb973b02f541168549cc110769fde86da3b37c1a6187d7fbfffe8bee3f72bea687d14786094ad0cb6a2cd7d4f2072c9989ec4d0c62b6ad81020bccd
|
7
|
+
data.tar.gz: 1e7f38e3f561a6f16304727fa89b2bbeab0b93b31e8e5a58633f533ba69e2a874e461f59bcf31d015d23382290e33b9b2ecfd007691fe6f5dc0961c98ca0d285
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.3
|
data/lib/rdf/turtle/writer.rb
CHANGED
@@ -189,7 +189,7 @@ module RDF::Turtle
|
|
189
189
|
# Remove lists that are referenced and have non-list properties;
|
190
190
|
# these are legal, but can't be serialized as lists
|
191
191
|
@lists.reject! do |node, list|
|
192
|
-
ref_count(node) > 0 &&
|
192
|
+
ref_count(node) > 0 && prop_count(node) > 0
|
193
193
|
end
|
194
194
|
|
195
195
|
order_subjects.each do |subject|
|
@@ -454,6 +454,44 @@ module RDF::Turtle
|
|
454
454
|
end
|
455
455
|
end
|
456
456
|
|
457
|
+
# Can subject be represented as a blankNodePropertyList?
|
458
|
+
def blankNodePropertyList?(resource, position)
|
459
|
+
resource.node? &&
|
460
|
+
!is_valid_list?(resource) &&
|
461
|
+
(!is_done?(resource) || position == :subject) &&
|
462
|
+
ref_count(resource) == (position == :object ? 1 : 0)
|
463
|
+
end
|
464
|
+
|
465
|
+
# Return the number of statements having this resource as a subject other than for list properties
|
466
|
+
# @return [Integer]
|
467
|
+
def prop_count(subject)
|
468
|
+
@subjects.fetch(subject, {}).
|
469
|
+
reject {|k, v| [RDF.type, RDF.first, RDF.rest].include?(k)}.
|
470
|
+
values.reduce(:+) || 0
|
471
|
+
end
|
472
|
+
|
473
|
+
# Return the number of times this node has been referenced in the object position
|
474
|
+
# @return [Integer]
|
475
|
+
def ref_count(resource)
|
476
|
+
@references.fetch(resource, 0)
|
477
|
+
end
|
478
|
+
|
479
|
+
# Increase the reference count of this resource
|
480
|
+
# @param [RDF::Resource] resource
|
481
|
+
# @return [Integer] resulting reference count
|
482
|
+
def bump_reference(resource)
|
483
|
+
@references[resource] = ref_count(resource) + 1
|
484
|
+
end
|
485
|
+
|
486
|
+
def is_done?(subject)
|
487
|
+
@serialized.include?(subject)
|
488
|
+
end
|
489
|
+
|
490
|
+
# Mark a subject as done.
|
491
|
+
def subject_done(subject)
|
492
|
+
@serialized[subject] = true
|
493
|
+
end
|
494
|
+
|
457
495
|
private
|
458
496
|
|
459
497
|
# Checks if l is a valid RDF list, i.e. no nodes have other properties.
|
@@ -478,7 +516,7 @@ module RDF::Turtle
|
|
478
516
|
def collection(node, position)
|
479
517
|
return false if !is_valid_list?(node)
|
480
518
|
return false if position == :subject && ref_count(node) > 0
|
481
|
-
return false if position == :object &&
|
519
|
+
return false if position == :object && prop_count(node) > 0
|
482
520
|
#log_debug("collection") {"#{node.to_ntriples}, #{position}"}
|
483
521
|
|
484
522
|
@output.write(position == :subject ? "(" : " (")
|
@@ -486,14 +524,6 @@ module RDF::Turtle
|
|
486
524
|
@output.write(')')
|
487
525
|
end
|
488
526
|
|
489
|
-
# Can subject be represented as a blankNodePropertyList?
|
490
|
-
def blankNodePropertyList?(resource, position)
|
491
|
-
resource.node? &&
|
492
|
-
!is_valid_list?(resource) &&
|
493
|
-
(!is_done?(resource) || position == :subject) &&
|
494
|
-
ref_count(resource) == (position == :object ? 1 : 0)
|
495
|
-
end
|
496
|
-
|
497
527
|
# Represent resource as a blankNodePropertyList
|
498
528
|
def blankNodePropertyList(resource, position)
|
499
529
|
return false unless blankNodePropertyList?(resource, position)
|
@@ -592,41 +622,5 @@ module RDF::Turtle
|
|
592
622
|
blankNodePropertyList(subject, :subject) || triples(subject)
|
593
623
|
@output.puts
|
594
624
|
end
|
595
|
-
|
596
|
-
# Return the number of statements having this resource as a subject
|
597
|
-
# @return [Integer]
|
598
|
-
def prop_count(subject)
|
599
|
-
@subjects.fetch(subject, {}).values.reduce(:+) || 0
|
600
|
-
end
|
601
|
-
|
602
|
-
# Return the number of statements having this resource as a subject other than for list properties
|
603
|
-
# @return [Integer]
|
604
|
-
def non_list_prop_count(subject)
|
605
|
-
@subjects.fetch(subject, {}).
|
606
|
-
reject {|k, v| [RDF.type, RDF.first, RDF.rest].include?(k)}.
|
607
|
-
values.reduce(:+) || 0
|
608
|
-
end
|
609
|
-
|
610
|
-
# Return the number of times this node has been referenced in the object position
|
611
|
-
# @return [Integer]
|
612
|
-
def ref_count(resource)
|
613
|
-
@references.fetch(resource, 0)
|
614
|
-
end
|
615
|
-
|
616
|
-
# Increase the reference count of this resource
|
617
|
-
# @param [RDF::Resource] resource
|
618
|
-
# @return [Integer] resulting reference count
|
619
|
-
def bump_reference(resource)
|
620
|
-
@references[resource] = ref_count(resource) + 1
|
621
|
-
end
|
622
|
-
|
623
|
-
def is_done?(subject)
|
624
|
-
@serialized.include?(subject)
|
625
|
-
end
|
626
|
-
|
627
|
-
# Mark a subject as done.
|
628
|
-
def subject_done(subject)
|
629
|
-
@serialized[subject] = true
|
630
|
-
end
|
631
625
|
end
|
632
626
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf-turtle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|