suma 0.5.31 → 0.5.33
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/lib/suma/term_extractor.rb +86 -19
- data/lib/suma/version.rb +1 -1
- 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: bd2e4a074e8d3b0ab67fd577a72084f05b6727c472b27d8372b8f22d0c98851c
|
|
4
|
+
data.tar.gz: fd67ff08c1e9607ec9e24ed66100dda235bfea0805b42427c83199313a868632
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3017ab40298248f60f38a32b25842535a47d72c36603de5c6c49b55d1a269341c497752e06c5f2bb372d0830155a49ecda7429310f0ffc44865ea8792398ab7b
|
|
7
|
+
data.tar.gz: 011e091b656afb963cd9c12156588a1fbf90a40ca08071c91ce58b20df3b8ba71464ccc075ca9d2486d263ac20e2400d5ac8b942d97e9d043566d2b3feee85f5
|
data/lib/suma/term_extractor.rb
CHANGED
|
@@ -300,33 +300,100 @@ module Suma
|
|
|
300
300
|
end
|
|
301
301
|
|
|
302
302
|
# The schema an imported declaration is declared in, resolved through
|
|
303
|
-
# +schema+'s
|
|
304
|
-
# carry: a local declaration wins;
|
|
305
|
-
#
|
|
306
|
-
#
|
|
307
|
-
#
|
|
303
|
+
# +schema+'s USE-FROM closure — the same resolution the source remark
|
|
304
|
+
# xrefs carry: a local declaration wins; otherwise the USE FROM edges
|
|
305
|
+
# (item-naming ones first, then bare ones) are walked transitively,
|
|
306
|
+
# and a single distinct declaring schema wins. nil leaves the citation
|
|
307
|
+
# qualified with the citing schema, since inventing an owner would be
|
|
308
|
+
# wrong (iso-10303#835: the declarer can sit more than one USE FROM
|
|
309
|
+
# away, and sibling branches must all be searched before settling).
|
|
308
310
|
def declaring_schema_id(schema, entity_id)
|
|
309
|
-
|
|
311
|
+
declarers = declaring_schemas(schema, entity_id, [])
|
|
312
|
+
declarers.uniq.one? ? declarers.first : nil
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
# Distinct schema ids within +schema+'s USE-FROM closure declaring
|
|
316
|
+
# +entity_id+. An interface whose item list names the declaration
|
|
317
|
+
# claims it outright (that is what the item list means in EXPRESS) —
|
|
318
|
+
# those sources are terminal candidates. Bare USE FROMs carry no
|
|
319
|
+
# claim, so they are walked; a bare source outside the manifest
|
|
320
|
+
# cannot be verified and stands as its own candidate. Each branch
|
|
321
|
+
# tracks its own visited list so sibling imports are searched
|
|
322
|
+
# independently; re-entering a schema on the same branch ends it.
|
|
323
|
+
def declaring_schemas(schema, entity_id, visited)
|
|
324
|
+
return [] if visited.include?(schema.id)
|
|
325
|
+
|
|
326
|
+
visited << schema.id
|
|
327
|
+
return [schema.id] if schema.entities.any? { |e| e.id == entity_id }
|
|
328
|
+
|
|
329
|
+
item_matches, bare_sources = use_from_sources(schema, entity_id)
|
|
330
|
+
return item_matches.uniq if item_matches.any?
|
|
331
|
+
|
|
332
|
+
walk_bare_sources(bare_sources, entity_id, visited)
|
|
333
|
+
end
|
|
310
334
|
|
|
335
|
+
def walk_bare_sources(bare_sources, entity_id, visited)
|
|
336
|
+
bare_sources.uniq.flat_map do |source|
|
|
337
|
+
loaded = loaded_schema(source)
|
|
338
|
+
if loaded
|
|
339
|
+
declaring_schemas(loaded, entity_id, visited.dup)
|
|
340
|
+
else
|
|
341
|
+
[source]
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
# The interface edges of +schema+ relevant to +entity_id+: the
|
|
347
|
+
# sources whose item list names it, and the bare-interface sources.
|
|
348
|
+
# Both USE FROM and REFERENCE FROM carry the declaring-schema edge —
|
|
349
|
+
# resource schemas import through REFERENCE FROM, and their citations
|
|
350
|
+
# mis-qualify exactly like USE FROM ones (iso-10303#835).
|
|
351
|
+
def use_from_sources(schema, entity_id)
|
|
311
352
|
item_matches = []
|
|
312
353
|
bare_sources = []
|
|
313
354
|
schema.interfaces.each do |interface|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
items = Array(interface.items)
|
|
318
|
-
if items.empty?
|
|
319
|
-
bare_sources << source
|
|
320
|
-
elsif items.any? { |item| import_item_id(item) == entity_id }
|
|
321
|
-
item_matches << source
|
|
355
|
+
case interface_claim(interface, entity_id)
|
|
356
|
+
when :item then item_matches << interface.schema.id
|
|
357
|
+
when :bare then bare_sources << interface.schema.id
|
|
322
358
|
end
|
|
323
359
|
end
|
|
324
360
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
361
|
+
[item_matches, bare_sources]
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# :item when the interface's item list names the declaration, :bare
|
|
365
|
+
# for a bare interface, nil when the interface is irrelevant to it.
|
|
366
|
+
def interface_claim(interface, entity_id)
|
|
367
|
+
source = interface.schema&.id
|
|
368
|
+
return nil unless source && %w[USE REFERENCE].include?(interface.kind)
|
|
369
|
+
|
|
370
|
+
items = Array(interface.items)
|
|
371
|
+
return :bare if items.empty?
|
|
372
|
+
return :item if item_names?(items, entity_id)
|
|
373
|
+
|
|
374
|
+
nil
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
def item_names?(items, entity_id)
|
|
378
|
+
items.any? { |item| import_item_id(item) == entity_id }
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
# Sibling schema by EXPRESS id, parsed on demand from the schema
|
|
382
|
+
# manifest and memoized — the walk only touches schemas a citation
|
|
383
|
+
# chain actually names.
|
|
384
|
+
def loaded_schema(id)
|
|
385
|
+
@loaded_schemas ||= {}
|
|
386
|
+
return @loaded_schemas[id] if @loaded_schemas.key?(id)
|
|
387
|
+
|
|
388
|
+
path = schema_manifest_paths[id]
|
|
389
|
+
@loaded_schemas[id] =
|
|
390
|
+
path && Expressir::Express::Parser.from_file(path)&.schemas&.first
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
def schema_manifest_paths
|
|
394
|
+
@schema_manifest_paths ||=
|
|
395
|
+
Expressir::SchemaManifest.from_file(@schema_manifest_file).schemas
|
|
396
|
+
.to_h { |entry| [entry.id, entry.path] }
|
|
330
397
|
end
|
|
331
398
|
|
|
332
399
|
# The imported declaration's name as written in the USE FROM list:
|
data/lib/suma/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: suma
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.33
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|