Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add fromTerm and fromQuad to DataFactory #449

Merged
merged 1 commit into from
Sep 18, 2024
Merged

Conversation

jeswr
Copy link
Collaborator

@jeswr jeswr commented Sep 18, 2024

Summary by CodeRabbit

  • New Features

    • Introduced fromTerm and fromQuad functions to enhance term and quad processing within the DataFactory module, improving interoperability with various representations.
  • Bug Fixes

    • Added error handling for unrecognized term types and invalid inputs in the new functions.
  • Tests

    • Implemented a comprehensive test suite for fromTerm and fromQuad, ensuring accurate processing of RDF terms and compatibility with the RDFJS data model.

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes introduce two new functions, fromTerm and fromQuad, to the DataFactory module in src/N3DataFactory.js, allowing for the conversion of various term representations into standardized internal representations. The fromTerm function handles different RDF term types, while the fromQuad function processes input quads by converting their components. Additionally, a new test suite is added to validate these methods against various RDF terms and ensure error handling for invalid inputs.

Changes

File Change Summary
src/N3DataFactory.js - Added fromTerm(term) and fromQuad(inQuad) functions to DataFactory.
- Modified const DataFactory to include the new functions.
test/N3DataFactory-test.js - Introduced a new test suite for fromTerm and fromQuad with multiple test cases for validation.
src/index.js - Added fromTerm(term) and fromQuad(quad) to the DataFactory class.

Possibly related issues

🐇 In the meadow, hops a little hare,
With new functions added, beyond compare.
From terms and quads, it weaves a tale,
In the world of RDF, it will prevail!
So let’s celebrate this joyful feat,
A DataFactory that’s now more complete! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 86a388e and 8e5719f.

Files selected for processing (2)
  • src/N3DataFactory.js (2 hunks)
  • test/N3DataFactory-test.js (2 hunks)
Additional comments not posted (9)
src/N3DataFactory.js (2)

392-406: LGTM! The fromTerm function is a valuable addition that enhances interoperability.

The function is well-structured and handles all possible cases correctly:

  • It checks if the input is already an N3.js term and returns it as-is, avoiding unnecessary conversions.
  • The switch statement covers all termTypes and calls the appropriate factory function for each.
  • It correctly handles nested quads by calling fromQuad.
  • It throws an error for unexpected termTypes, providing clear feedback for potential issues.

Overall, this function provides a clear and consistent way to convert terms from other libraries into N3.js terms, improving the library's interoperability and ease of use.


408-416: LGTM! The fromQuad function is a great complement to fromTerm and ensures consistent quad representation.

The function is well-structured and handles the conversion correctly:

  • It checks if the input is already an N3.js quad and returns it as-is, avoiding unnecessary conversions.
  • It verifies that the input has a termType of Quad and throws an error otherwise, providing clear feedback for potential issues.
  • It constructs a new N3.js quad by converting each component using fromTerm, ensuring that the resulting quad is fully converted to N3.js terms.

This function, together with fromTerm, provides a comprehensive solution for converting terms and quads from other libraries into their N3.js equivalents, promoting consistency and interoperability.

test/N3DataFactory-test.js (7)

199-208: LGTM!

The test case thoroughly checks the behavior of fromTerm with a named node, including equality and reference identity for both the N3 and RDFJS data models.


210-219: LGTM!

The test case thoroughly checks the behavior of fromTerm with a blank node, including equality and reference identity for both the N3 and RDFJS data models.


221-230: LGTM!

The test case thoroughly checks the behavior of fromTerm with a literal, including equality and reference identity for both the N3 and RDFJS data models.


232-241: LGTM!

The test case thoroughly checks the behavior of fromTerm with a variable, including equality and reference identity for both the N3 and RDFJS data models.


243-252: LGTM!

The test case thoroughly checks the behavior of fromTerm with a default graph, including equality and reference identity for both the N3 and RDFJS data models.


254-258: LGTM!

The test case checks that fromTerm and fromQuad throw errors when provided with unknown terms or invalid inputs, ensuring proper error handling.


260-284: LGTM!

The test case thoroughly checks the behavior of fromTerm and fromQuad with a quad, including equality and reference identity for both the N3 and RDFJS data models.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jeswr jeswr requested a review from RubenVerborgh September 18, 2024 11:11
@jeswr jeswr linked an issue Sep 18, 2024 that may be closed by this pull request
@jeswr jeswr merged commit 48cb127 into main Sep 18, 2024
16 checks passed
@jeswr jeswr deleted the feat/fromTerm-fromQuad branch September 18, 2024 11:37
Copy link

🎉 This PR is included in version 1.22.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fromTerm and fromQuad are missing from DataFactory
2 participants