Rewrite prefix generation and replacement logic#1539
Open
Rewrite prefix generation and replacement logic#1539
Conversation
Collaborator
Author
|
- Add splitIri, generatePrefix, commonPrefixes utility modules - Add PrefixLookup class for fast Map-based prefix lookups - Rewrite generatePrefixes to use splitIri and generatePrefix - Rewrite replacePrefixes to use PrefixLookup and splitIri - Change usePrefixes/prefixesAtom to return PrefixLookup - Remove __matches from PrefixTypeConfig - Simplify saveConfigurationToFile and useImportConnectionFile - Add backward compatibility tests for legacy __matches data
bfa1d4f to
63011a9
Compare
82efdf6 to
9dc2a68
Compare
- Reject IRIs whose local value contains characters invalid in RDF prefixed names: spaces, angle brackets, curly braces, pipes, carets, backticks, and backslashes - Allow underscores, hyphens, periods, percent-encoded sequences, Unicode letters, and middle dots - Remove duplicate tests that were outside the describe block
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1539 +/- ##
===========================================
+ Coverage 47.81% 65.41% +17.59%
===========================================
Files 382 359 -23
Lines 8525 7968 -557
Branches 3159 2900 -259
===========================================
+ Hits 4076 5212 +1136
+ Misses 3070 1991 -1079
+ Partials 1379 765 -614
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| /** Abbreviates a segment to the first letter of each word. */ | ||
| function abbreviate(segment: string): string { | ||
| const words = splitSegmentIntoWords(segment); |
There was a problem hiding this comment.
I think this entire function can be summarized as:
return sanitizePrefix(
splitSegmentIntoWords(segment)
.map(w => w.charAt(0))
.join("")
)
imho, it's easier to reason about it if it's written this way, because these two returns don't look the same semantically. Makes me even question — do we not sanitizePrefix if more than one word?
| } | ||
|
|
||
| return updatedPrefixes.values().toArray(); | ||
| let i = 2; |
There was a problem hiding this comment.
imo worth leaving a comment wrt the magic number
| } | ||
|
|
||
| // Reject URIs without a real origin (e.g. urn:, mailto:, custom-scheme:) | ||
| if (!url.origin || url.origin === "null") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
splitIri,generatePrefix, andcommonPrefixesutility modulesPrefixLookupclass for fast Map-based prefix lookupsgeneratePrefixesto usesplitIriandgeneratePrefixreplacePrefixesto usePrefixLookupandsplitIriusePrefixes/prefixesAtomto returnPrefixLookup__matchesfromPrefixTypeConfigsaveConfigurationToFileanduseImportConnectionFilesoccer,soccer2,soccer3)__matchesdataValidation
splitIri,generatePrefix,PrefixLookup,commonPrefixes, prefix uniqueness, entity ID prefix generation, local value validation, and backward compatibility with legacy dataPrefix generation examples:
http://www.example.com/soccer/ontology/Leaguesoccerhttp://www.schema.org/Cityschemaresourcesegmenthttp://data.nobelprize.org/resource/country/Francecountryclasssegmenthttps://dbpedia.org/class/yago/Record106647206yagohttp://example.org/2024/01/schema#Thingschemahttp://kelvinlawrence.net/air-routes/datatypeProperty/nameairdphttp://kelvinlawrence.net/air-routes/objectProperty/routeairophttp://example.org/my-special_ns.v2/Itemmyhttp://www.example.com/soccer/ontology/Leaguesoccerhttp://www.example.com/soccer/resource#EPLsoccer2http://www.example.com/soccer/class#Teamsoccer3Local value validation (accepted):
my_item,my-item,v2.0,caf%C3%A9,café,item·1Local value validation (rejected → no prefix generated):
my item,a<b,a{b},a|b,a^b,a`b,a\bRelated Issues
Check List
license.
pnpm checksto ensure code compiles and meets standards.pnpm testto check if all tests are passing.Changelog.md.