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

rml:Target: add more properties (write mode) #49

Closed
ghsnd opened this issue Mar 12, 2024 · 1 comment
Closed

rml:Target: add more properties (write mode) #49

ghsnd opened this issue Mar 12, 2024 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ghsnd
Copy link
Contributor

ghsnd commented Mar 12, 2024

For some targets it might make sense to specify some extra properties. I have this use case where I want to append output to target file x, but overwrite target file y if it exists. So for files there are the typical write modes, e.g. like the python file modes w, a, etc.

In the spec these properties might translate to properties that apply to other kinds of targets as well, for instance databases.

@DylanVanAssche
Copy link
Collaborator

Related to kg-construct/rml-core#113

What about adding to rml:Target:

  • rml:mode: the mode to use when accessing the file

This property has the range of:

  • rml:Read: read-only mode (r). Start beginning of file. Not useful for targets. File must exist.
  • rml:ReadWrite: read-write mode (r+). Start beginning of file, no truncation. Only write part is useful for targets. File must exist.
  • rml:Write: write mode (w). Truncate/create file and start at the beginning to add new data.
  • rml:WriteRead: write-read mode (w). Truncate/create file and start at the beginning to add new data. Only write part is useful for targets
  • rml:Append: append-only mode. Existing file is kept and new data is appended at the end. File is created if not exist.
  • rml:AppendRead: append-read mode. Existing file is kept and new data is appended at the end. File is created if not exist.

These semantics are derived from fopen():

     ``r''   Open text file for reading.  The stream is positioned at the
             beginning of the file.

     ``r+''  Open for reading and writing.  The stream is positioned at the
             beginning of the file.

     ``w''   Truncate to zero length or create text file for writing.  The
             stream is positioned at the beginning of the file.

     ``w+''  Open for reading and writing.  The file is created if it does not
             exist, otherwise it is truncated.  The stream is positioned at
             the beginning of the file.

     ``a''   Open for writing.  The file is created if it does not exist.  The
             stream is positioned at the end of the file.  Subsequent writes
             to the file will always end up at the then current end of file,
             irrespective of any intervening [fseek(3)](https://www.manpagez.com/man/3/fseek/) or similar.

     ``a+''  Open for reading and writing.  The file is created if it does not
             exist.  The stream is positioned at the end of the file.  Subse-
             quent writes to the file will always end up at the then current
             end of file, irrespective of any intervening [fseek(3)](https://www.manpagez.com/man/3/fseek/) or similar.

Source: https://www.manpagez.com/man/3/fopen/

If no access mode is provided, the file is opened in rml:Write mode for rml:Target.

Note: rml:Source does have rml:mode since it always open the source in read-only mode.

@DylanVanAssche DylanVanAssche added enhancement New feature or request help wanted Extra attention is needed labels Mar 15, 2024
DylanVanAssche added a commit that referenced this issue Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants