[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-02-16 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/commons-rdf/pull/27


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-02-08 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r100211712
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -22,6 +22,124 @@
 import java.util.Optional;
 
 /**
+ * An RDF syntax, e.g. as used for parsing and writing RDF.
+ * 
+ * An RDF syntax is uniquely identified by its {@link #mediaType()}, and 
has a
+ * suggested {@link #fileExtension()}.
+ * 
+ * Some of the RDF syntaxes may {@link #supportsDataset()}, meaning they 
can
+ * represent {@link Quad}s.
+ * 
+ * An enumeration of the official RDF 1.1 syntaxes is available in 
+ * {@link OfficialRDFSyntax} - for convenience they are also accessible
+ * as constants here, e.g. RDFSyntax.JSONLD.
+ * 
+ */
+public interface RDFSyntax {
+ 
+public static OfficialRDFSyntax JSONLD = OfficialRDFSyntax.JSONLD;
+public static OfficialRDFSyntax TURTLE = OfficialRDFSyntax.TURTLE;
+public static OfficialRDFSyntax NQUADS = OfficialRDFSyntax.NQUADS;
+public static OfficialRDFSyntax NTRIPLES = OfficialRDFSyntax.NTRIPLES;
+public static OfficialRDFSyntax RDFA_HTML = 
OfficialRDFSyntax.RDFA_HTML;
+public static OfficialRDFSyntax RDFA_XHTML = 
OfficialRDFSyntax.RDFA_XHTML;
+public static OfficialRDFSyntax RDFXML = OfficialRDFSyntax.RDFXML;
+public static OfficialRDFSyntax TRIG = OfficialRDFSyntax.TRIG;
+
+/**
+ * A short name of the RDF Syntax.
+ * 
+ * The name typically corresponds to the {@link Enum#name()} of for
+ * {@link OfficialRDFSyntax}, e.g. JSONLD.
+ * 
+ * @return Short name for RDF syntax
+ */
+public String name();
+
+/**
+ * The title of the RDF Syntax.
+ * 
+ * This is generally the title of the corresponding standard, 
+ * e.g. RDF 1.1 Turtle.
+ * 
+ * @return Title of RDF Syntax
+ */
+public String title();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA media 
type for
+ * the RDF syntax.
+ * 
+ * The media type can be used as part of Content-Type and
+ * Accept for content negotiation in the
+ * https://tools.ietf.org/html/rfc7231#section-3.1.1.1;>HTTP
+ * protocol.
+ */
+public String mediaType();
--- End diff --

So my suggestion was that `mediaType()` has "The IANA media type" and 
similar for `fileExtension()`. Arbitrary "other" media types and extensions 
would have to be in a different method - perhaps the plural `mediaTypes()` and 
`fileExtensions()`?

There is nothing stopping a parser from supporting other media types and 
file extensions, but I'm not sure why they also need to be present in the 
`RDFSyntax` interface, which main purpose is to hard-code a syntax for reading 
(and maybe more so writing).

The previously proposed 
[RDFParser](https://github.com/apache/commons-rdf/blob/master/api/src/main/java/org/apache/commons/rdf/experimental/RDFParser.java)
 interface - which I hope we can discuss in a separate pull request / Jira 
Issue - supports  both `contentType(String contentType)` and 
`contentType(RDFSyntax rdfSyntax)`.

It also has for `source(IRI)`:

> * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)} 
MAY
> * be set before calling {@link #parse()}, in which case that type MAY 
be
> * used for content negotiation (e.g. Accept header in 
HTTP),
> * and SHOULD be used for selecting the RDFSyntax.


while for `source(Path)` (a file) it changes to SHOULD (as file extensions 
are fragile)

> * The {@link #contentType(RDFSyntax)} or {@link #contentType(String)}
> * SHOULD be set before calling {@link #parse()}.

This hints that a parser is able to do file extension or file magic, but is 
not required to. Both RDF4J and Jena implementations have different mechanisms 
for this, e.g. 
[RDF4JParser](https://github.com/apache/commons-rdf/blob/master/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java#L140)
 falls back to `Rio.getParserFormatForFileName()` based on path filename if no 
content type is specified - which would use RDF4J's extended list of file 
extensions and formats.

Obviously this would be easy to implement consistently for our hard-coded 
w3c-standardized file extensions (and we could document that), but much harder 
for arbitrary "other" extensions.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.

[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-02-08 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r100209281
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -91,7 +148,30 @@
  * Datasets.
  */
 public boolean supportsDataset();
+   
+/**
+ * Return the RDF 1.1 serialization syntaxes.
+ * 
+ * This lists the W3C standardized RDF 1.1 syntaxes like {@link 
#TURTLE} and
+ * {@link #JSONLD}. Note the existence of other RDF syntaxes that are 
not
+ * included here, e.g. http://www.w3.org/TeamSubmission/n3/;>N3 and
+ * https://en.wikipedia.org/wiki/TriX_%28syntax%29;>TriX.
+ * 
+ * The syntaxes returned only support the {@link #mediaType()}
+ * and {@link #fileExtension()} as defined in the corresponding 
+ * W3C specification.
+ * 
+ * @return
+ *  A set of the official RDF 1.1 {@link RDFSyntax}es.
+ * 
+ * @see https://www.w3.org/TR/rdf11-primer/#section-graph-syntax;>RDF
+ *  1.1 Primer
+ * @see org.apache.commons.rdf.experimental.RDFParser
+ */
 
+public static Set w3cSyntaxes() {
--- End diff --

`W3CRDFSyntax` is package-protected. It was moved it out followingyour 
advice, but I don't see any win in making it `public` as it has no additional 
methods (and shouldn't have).

If we make it public and remove `w3cSyntaxes()` , then there's not much 
more any point to have the proxy constants `RDFSyntax.TURTLE` etc. as they 
would also then be made public at `W3CRDFSyntax.TURTLE` etc - which - not 
withstanding the CAPSISSUE - is not as accessible for the 95% use cases of 
parsing/writing a RDF 1.1 syntax.




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-02-08 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r100208441
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -178,17 +206,62 @@ private RDFSyntax(final String name, final String 
mediaType, final String fileEx
  * The fileExtension is compared in lower case, therefore 
it
  * might not be equal to the {@link RDFSyntax#fileExtension} of the 
returned
  * RDFSyntax.
+ * 
+ * The list of syntaxes supported is at least those returned by
+ * {@link #w3cSyntaxes()}.
  * 
  * @param fileExtension
  *The fileExtension to match, starting with .
  * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} 
which has
- * a matching {@link RDFSyntax#fileExtension}, otherwise
+ * a matching {@link RDFSyntax#fileExtension()}, otherwise
  * {@link Optional#empty()} indicating that no matching file
  * extension was found.
  */
 public static Optional byFileExtension(final String 
fileExtension) {
-final String ext = fileExtension.toLowerCase(Locale.ENGLISH);
-return Arrays.stream(RDFSyntax.values()).filter(t -> 
t.fileExtension.equals(ext)).findAny();
+final String ext = fileExtension.toLowerCase(Locale.ROOT);
+return w3cSyntaxes().stream().filter(t -> 
t.fileExtension().equals(ext))
+.findAny();
+}
+
+/**
+ * Return the RDFSyntax with the specified {@link #name()}.
+ * 
+ * The list of syntaxes supported is at least those returned by
--- End diff --

Changed to 
> This method support all syntaxes returned by {@link #w3cSyntaxes()}

There is no good way from a static class method to allow user extension; at 
least without having a discovery mechanism (classpath sensitive) or mutable 
setters/registrations (initialization sensitive) - I would argue it is out of 
scope for this particular method to support that, as Commons RDF only  target 
RDF 1.1.  

If you want we could change these lookup method to take a variable/optional 
list of `Iterable` as parameters? 

(The parser/writer methods would with this PR support `RDFSyntax` from 
"elsewhere" - e.g. we could return supported syntaxes from each `RDF` instance)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread ansell
Github user ansell commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95894599
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -178,17 +206,62 @@ private RDFSyntax(final String name, final String 
mediaType, final String fileEx
  * The fileExtension is compared in lower case, therefore 
it
  * might not be equal to the {@link RDFSyntax#fileExtension} of the 
returned
  * RDFSyntax.
+ * 
+ * The list of syntaxes supported is at least those returned by
+ * {@link #w3cSyntaxes()}.
  * 
  * @param fileExtension
  *The fileExtension to match, starting with .
  * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} 
which has
- * a matching {@link RDFSyntax#fileExtension}, otherwise
+ * a matching {@link RDFSyntax#fileExtension()}, otherwise
  * {@link Optional#empty()} indicating that no matching file
  * extension was found.
  */
 public static Optional byFileExtension(final String 
fileExtension) {
-final String ext = fileExtension.toLowerCase(Locale.ENGLISH);
-return Arrays.stream(RDFSyntax.values()).filter(t -> 
t.fileExtension.equals(ext)).findAny();
+final String ext = fileExtension.toLowerCase(Locale.ROOT);
+return w3cSyntaxes().stream().filter(t -> 
t.fileExtension().equals(ext))
+.findAny();
+}
+
+/**
+ * Return the RDFSyntax with the specified {@link #name()}.
+ * 
+ * The list of syntaxes supported is at least those returned by
--- End diff --

There doesn't look to be any way to extend that set from a user point of 
view. This wording implies there is a way.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread ansell
Github user ansell commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95893698
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -91,7 +148,30 @@
  * Datasets.
  */
 public boolean supportsDataset();
+   
+/**
+ * Return the RDF 1.1 serialization syntaxes.
+ * 
+ * This lists the W3C standardized RDF 1.1 syntaxes like {@link 
#TURTLE} and
+ * {@link #JSONLD}. Note the existence of other RDF syntaxes that are 
not
+ * included here, e.g. http://www.w3.org/TeamSubmission/n3/;>N3 and
+ * https://en.wikipedia.org/wiki/TriX_%28syntax%29;>TriX.
+ * 
+ * The syntaxes returned only support the {@link #mediaType()}
+ * and {@link #fileExtension()} as defined in the corresponding 
+ * W3C specification.
+ * 
+ * @return
+ *  A set of the official RDF 1.1 {@link RDFSyntax}es.
+ * 
+ * @see https://www.w3.org/TR/rdf11-primer/#section-graph-syntax;>RDF
+ *  1.1 Primer
+ * @see org.apache.commons.rdf.experimental.RDFParser
+ */
 
+public static Set w3cSyntaxes() {
--- End diff --

This is unnecessary duplication


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread acoburn
Github user acoburn commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95862649
  
--- Diff: api/src/test/java/org/apache/commons/rdf/api/RDFSyntaxTest.java 
---
@@ -114,8 +116,7 @@ public void name() throws Exception {
 
 @Test
 public void valueOf() throws Exception {
-assertEquals(RDFSyntax.TURTLE, RDFSyntax.valueOf("TURTLE"));
-// No need to test all of them, we'll trust Enum
+assertEquals(RDFSyntax.TURTLE, RDFSyntax.byName("TURTLE"));
--- End diff --

`RDFSyntax::byName` returns an `Optional`. Perhaps you mean:

assertEquals(RDFSyntax.TURTLE, RDFSyntax.byName("TURTLE").get());


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95843235
  
--- Diff: 
simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
 ---
@@ -240,7 +240,7 @@ public T rdfTermFactory(RDF rdfTermFactory) {
 public T contentType(RDFSyntax rdfSyntax) throws 
IllegalArgumentException {
 AbstractRDFParser c = clone();
 c.contentTypeSyntax = Optional.ofNullable(rdfSyntax);
-c.contentType = c.contentTypeSyntax.map(syntax -> 
syntax.mediaType);
+c.contentType = c.contentTypeSyntax.map(syntax -> 
syntax.mediaType());
 return c.asT();
--- End diff --

It's just a generics trick so that subclasses of `AbstractRDFParser` can 
return their own type in all the setter methods rather than `RDFParser` or 
`AbstractRDFParser`, which would hide any additional methods they specialize 
with.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95843006
  
--- Diff: 
simple/src/main/java/org/apache/commons/rdf/simple/experimental/AbstractRDFParser.java
 ---
@@ -240,7 +240,7 @@ public T rdfTermFactory(RDF rdfTermFactory) {
 public T contentType(RDFSyntax rdfSyntax) throws 
IllegalArgumentException {
 AbstractRDFParser c = clone();
--- End diff --

No, but cloning means the `RDFParser` is immutable and can be reused in a 
thread-safe manner, e.g. if parsing many Turtle files in the same folder. So 
what is worse..:

* a) Creating 1000 RDFParser instances, setting all parameters every time, 
and remember not to reuse/share in multiple threads.
* b) Create a single base RDFParser instance with the common settings, then 
specialize only what is needed for each file to use in any thread at any time. 
(e.g. called from a within a `Stream.parallell().map()`

I think the overhead of cloning here is pretty much equivalent, e.g. `1000` 
instances, or `1005` instances.  

If you are parsing just a single file then I don't think the inefficiency 
of the cloning makes a big difference - that is unless you are making a very 
snappy UI or something.

Let's change this to mutable only if benchmark numbers show a problem?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95841290
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -34,7 +152,7 @@
  *  1.1 Primer
  * @see org.apache.commons.rdf.experimental.RDFParser
  */
-public enum RDFSyntax {
+  public enum OfficialRDFSyntax implements RDFSyntax {
--- End diff --

I also wanted to list the `IRI` identifying the syntaxes, but then I would 
need a complete `IRIImpl` within `api/` .. or move `W3CRDFSyntax` to `simple/`. 
 (or.. awkwardly.. ask for an `RDF` instance :))


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95841065
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -22,6 +22,124 @@
 import java.util.Optional;
 
 /**
+ * An RDF syntax, e.g. as used for parsing and writing RDF.
+ * 
+ * An RDF syntax is uniquely identified by its {@link #mediaType()}, and 
has a
+ * suggested {@link #fileExtension()}.
+ * 
+ * Some of the RDF syntaxes may {@link #supportsDataset()}, meaning they 
can
+ * represent {@link Quad}s.
+ * 
+ * An enumeration of the official RDF 1.1 syntaxes is available in 
+ * {@link OfficialRDFSyntax} - for convenience they are also accessible
+ * as constants here, e.g. RDFSyntax.JSONLD.
+ * 
+ */
+public interface RDFSyntax {
+ 
+public static OfficialRDFSyntax JSONLD = OfficialRDFSyntax.JSONLD;
+public static OfficialRDFSyntax TURTLE = OfficialRDFSyntax.TURTLE;
+public static OfficialRDFSyntax NQUADS = OfficialRDFSyntax.NQUADS;
+public static OfficialRDFSyntax NTRIPLES = OfficialRDFSyntax.NTRIPLES;
+public static OfficialRDFSyntax RDFA_HTML = 
OfficialRDFSyntax.RDFA_HTML;
+public static OfficialRDFSyntax RDFA_XHTML = 
OfficialRDFSyntax.RDFA_XHTML;
+public static OfficialRDFSyntax RDFXML = OfficialRDFSyntax.RDFXML;
+public static OfficialRDFSyntax TRIG = OfficialRDFSyntax.TRIG;
+
+/**
+ * A short name of the RDF Syntax.
+ * 
+ * The name typically corresponds to the {@link Enum#name()} of for
+ * {@link OfficialRDFSyntax}, e.g. JSONLD.
+ * 
+ * @return Short name for RDF syntax
+ */
+public String name();
+
+/**
+ * The title of the RDF Syntax.
+ * 
+ * This is generally the title of the corresponding standard, 
+ * e.g. RDF 1.1 Turtle.
+ * 
+ * @return Title of RDF Syntax
+ */
+public String title();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA media 
type for
+ * the RDF syntax.
+ * 
+ * The media type can be used as part of Content-Type and
+ * Accept for content negotiation in the
+ * https://tools.ietf.org/html/rfc7231#section-3.1.1.1;>HTTP
+ * protocol.
+ */
+public String mediaType();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA-registered
+ * file extension.
+ * 
+ * The file extension includes the leading period, e.g. 
.jsonld
+ */
+public String fileExtension();
+
+/**
+ * Indicate if this RDF syntax supports
+ * https://www.w3.org/TR/rdf11-concepts/#section-dataset;>RDF
+ * Datasets.
+ */
+public boolean supportsDataset();
+
+
+/**
+ * Return the RDFSyntax with the specified media type.
+ * 
+ * The mediaType is compared in lower case, therefore it 
might
+ * not be equal to the {@link RDFSyntax#mediaType} of the returned
+ * RDFSyntax.
+ * 
+ * For convenience matching of media types used in a
+ * Content-Type header, if the mediaType 
contains
+ * the characters ;, , or white space, only 
the
+ * part of the string to the left of those characters are considered.
+ * 
+ * @param mediaType
+ *The media type to match
+ * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} 
which has
+ * a matching {@link RDFSyntax#mediaType}, otherwise
+ * {@link Optional#empty()} indicating that no matching syntax 
was
+ * found.
+ */
+public static Optional byMediaType(String mediaType) {
+final String type = 
mediaType.toLowerCase(Locale.ENGLISH).split("\\s*[;,]", 2)[0];
+return Arrays.stream(OfficialRDFSyntax.values()).filter(t -> 
t.mediaType().equals(type))
--- End diff --

Changed `OfficialRDFSyntax`  to a package-protected class `W3CRDFSyntax` 
and referred to its instances.

`values()` renamed to `w3cSyntaxes()` which return a `Set`. I 
don't think we need to make a `HashMap` from media type/extension to 
`RDFSyntax` as there's only 8 instances to iterate over anyway.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org


[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95840655
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -22,6 +22,124 @@
 import java.util.Optional;
 
 /**
+ * An RDF syntax, e.g. as used for parsing and writing RDF.
+ * 
+ * An RDF syntax is uniquely identified by its {@link #mediaType()}, and 
has a
+ * suggested {@link #fileExtension()}.
+ * 
+ * Some of the RDF syntaxes may {@link #supportsDataset()}, meaning they 
can
+ * represent {@link Quad}s.
+ * 
+ * An enumeration of the official RDF 1.1 syntaxes is available in 
+ * {@link OfficialRDFSyntax} - for convenience they are also accessible
+ * as constants here, e.g. RDFSyntax.JSONLD.
+ * 
+ */
+public interface RDFSyntax {
+ 
+public static OfficialRDFSyntax JSONLD = OfficialRDFSyntax.JSONLD;
+public static OfficialRDFSyntax TURTLE = OfficialRDFSyntax.TURTLE;
+public static OfficialRDFSyntax NQUADS = OfficialRDFSyntax.NQUADS;
+public static OfficialRDFSyntax NTRIPLES = OfficialRDFSyntax.NTRIPLES;
+public static OfficialRDFSyntax RDFA_HTML = 
OfficialRDFSyntax.RDFA_HTML;
+public static OfficialRDFSyntax RDFA_XHTML = 
OfficialRDFSyntax.RDFA_XHTML;
+public static OfficialRDFSyntax RDFXML = OfficialRDFSyntax.RDFXML;
+public static OfficialRDFSyntax TRIG = OfficialRDFSyntax.TRIG;
+
+/**
+ * A short name of the RDF Syntax.
+ * 
+ * The name typically corresponds to the {@link Enum#name()} of for
+ * {@link OfficialRDFSyntax}, e.g. JSONLD.
+ * 
+ * @return Short name for RDF syntax
+ */
+public String name();
+
+/**
+ * The title of the RDF Syntax.
+ * 
+ * This is generally the title of the corresponding standard, 
+ * e.g. RDF 1.1 Turtle.
+ * 
+ * @return Title of RDF Syntax
+ */
+public String title();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA media 
type for
+ * the RDF syntax.
+ * 
+ * The media type can be used as part of Content-Type and
+ * Accept for content negotiation in the
+ * https://tools.ietf.org/html/rfc7231#section-3.1.1.1;>HTTP
+ * protocol.
+ */
+public String mediaType();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA-registered
+ * file extension.
+ * 
+ * The file extension includes the leading period, e.g. 
.jsonld
+ */
+public String fileExtension();
+
+/**
+ * Indicate if this RDF syntax supports
+ * https://www.w3.org/TR/rdf11-concepts/#section-dataset;>RDF
+ * Datasets.
+ */
+public boolean supportsDataset();
+
+
+/**
+ * Return the RDFSyntax with the specified media type.
+ * 
+ * The mediaType is compared in lower case, therefore it 
might
+ * not be equal to the {@link RDFSyntax#mediaType} of the returned
+ * RDFSyntax.
+ * 
+ * For convenience matching of media types used in a
+ * Content-Type header, if the mediaType 
contains
+ * the characters ;, , or white space, only 
the
+ * part of the string to the left of those characters are considered.
+ * 
+ * @param mediaType
+ *The media type to match
+ * @return If {@link Optional#isPresent()}, the {@link RDFSyntax} 
which has
+ * a matching {@link RDFSyntax#mediaType}, otherwise
+ * {@link Optional#empty()} indicating that no matching syntax 
was
+ * found.
+ */
+public static Optional byMediaType(String mediaType) {
+final String type = 
mediaType.toLowerCase(Locale.ENGLISH).split("\\s*[;,]", 2)[0];
--- End diff --

I changed it to only support the media type format as @acoburn  suggests, 
not the content type which can list multiple types (parsing a `Content-Type` 
header properly requires more work!)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95840484
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -22,6 +22,124 @@
 import java.util.Optional;
 
 /**
+ * An RDF syntax, e.g. as used for parsing and writing RDF.
+ * 
+ * An RDF syntax is uniquely identified by its {@link #mediaType()}, and 
has a
+ * suggested {@link #fileExtension()}.
+ * 
+ * Some of the RDF syntaxes may {@link #supportsDataset()}, meaning they 
can
+ * represent {@link Quad}s.
+ * 
+ * An enumeration of the official RDF 1.1 syntaxes is available in 
+ * {@link OfficialRDFSyntax} - for convenience they are also accessible
+ * as constants here, e.g. RDFSyntax.JSONLD.
+ * 
+ */
+public interface RDFSyntax {
+ 
+public static OfficialRDFSyntax JSONLD = OfficialRDFSyntax.JSONLD;
+public static OfficialRDFSyntax TURTLE = OfficialRDFSyntax.TURTLE;
+public static OfficialRDFSyntax NQUADS = OfficialRDFSyntax.NQUADS;
+public static OfficialRDFSyntax NTRIPLES = OfficialRDFSyntax.NTRIPLES;
+public static OfficialRDFSyntax RDFA_HTML = 
OfficialRDFSyntax.RDFA_HTML;
+public static OfficialRDFSyntax RDFA_XHTML = 
OfficialRDFSyntax.RDFA_XHTML;
+public static OfficialRDFSyntax RDFXML = OfficialRDFSyntax.RDFXML;
+public static OfficialRDFSyntax TRIG = OfficialRDFSyntax.TRIG;
+
+/**
+ * A short name of the RDF Syntax.
+ * 
+ * The name typically corresponds to the {@link Enum#name()} of for
+ * {@link OfficialRDFSyntax}, e.g. JSONLD.
+ * 
+ * @return Short name for RDF syntax
+ */
+public String name();
+
+/**
+ * The title of the RDF Syntax.
+ * 
+ * This is generally the title of the corresponding standard, 
+ * e.g. RDF 1.1 Turtle.
+ * 
+ * @return Title of RDF Syntax
+ */
+public String title();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA media 
type for
+ * the RDF syntax.
+ * 
+ * The media type can be used as part of Content-Type and
+ * Accept for content negotiation in the
+ * https://tools.ietf.org/html/rfc7231#section-3.1.1.1;>HTTP
+ * protocol.
+ */
+public String mediaType();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA-registered
+ * file extension.
+ * 
+ * The file extension includes the leading period, e.g. 
.jsonld
+ */
+public String fileExtension();
+
+/**
+ * Indicate if this RDF syntax supports
+ * https://www.w3.org/TR/rdf11-concepts/#section-dataset;>RDF
+ * Datasets.
+ */
+public boolean supportsDataset();
+
+
--- End diff --

I think that is out of scope for now, as Commons RDF does not specify 
namespace preservation yet anywhere else.

Let's revisit that when we make `RDFWriter` where it might be a bit more 
natural than in `RDFParser` (although I know RDF4J can preserve parsed 
namespaces)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95840249
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -22,6 +22,124 @@
 import java.util.Optional;
 
 /**
+ * An RDF syntax, e.g. as used for parsing and writing RDF.
+ * 
+ * An RDF syntax is uniquely identified by its {@link #mediaType()}, and 
has a
+ * suggested {@link #fileExtension()}.
+ * 
+ * Some of the RDF syntaxes may {@link #supportsDataset()}, meaning they 
can
+ * represent {@link Quad}s.
+ * 
+ * An enumeration of the official RDF 1.1 syntaxes is available in 
+ * {@link OfficialRDFSyntax} - for convenience they are also accessible
+ * as constants here, e.g. RDFSyntax.JSONLD.
+ * 
+ */
+public interface RDFSyntax {
+ 
+public static OfficialRDFSyntax JSONLD = OfficialRDFSyntax.JSONLD;
+public static OfficialRDFSyntax TURTLE = OfficialRDFSyntax.TURTLE;
+public static OfficialRDFSyntax NQUADS = OfficialRDFSyntax.NQUADS;
+public static OfficialRDFSyntax NTRIPLES = OfficialRDFSyntax.NTRIPLES;
+public static OfficialRDFSyntax RDFA_HTML = 
OfficialRDFSyntax.RDFA_HTML;
+public static OfficialRDFSyntax RDFA_XHTML = 
OfficialRDFSyntax.RDFA_XHTML;
+public static OfficialRDFSyntax RDFXML = OfficialRDFSyntax.RDFXML;
+public static OfficialRDFSyntax TRIG = OfficialRDFSyntax.TRIG;
+
+/**
+ * A short name of the RDF Syntax.
+ * 
+ * The name typically corresponds to the {@link Enum#name()} of for
+ * {@link OfficialRDFSyntax}, e.g. JSONLD.
+ * 
+ * @return Short name for RDF syntax
+ */
+public String name();
+
+/**
+ * The title of the RDF Syntax.
+ * 
+ * This is generally the title of the corresponding standard, 
+ * e.g. RDF 1.1 Turtle.
+ * 
+ * @return Title of RDF Syntax
+ */
+public String title();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA media 
type for
+ * the RDF syntax.
+ * 
+ * The media type can be used as part of Content-Type and
+ * Accept for content negotiation in the
+ * https://tools.ietf.org/html/rfc7231#section-3.1.1.1;>HTTP
+ * protocol.
+ */
+public String mediaType();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA-registered
+ * file extension.
+ * 
+ * The file extension includes the leading period, e.g. 
.jsonld
+ */
+public String fileExtension();
--- End diff --

No :-)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[GitHub] commons-rdf pull request #27: COMMONSRDF-47 RDFSyntax as an interface

2017-01-12 Thread stain
Github user stain commented on a diff in the pull request:

https://github.com/apache/commons-rdf/pull/27#discussion_r95840179
  
--- Diff: api/src/main/java/org/apache/commons/rdf/api/RDFSyntax.java ---
@@ -22,6 +22,124 @@
 import java.util.Optional;
 
 /**
+ * An RDF syntax, e.g. as used for parsing and writing RDF.
+ * 
+ * An RDF syntax is uniquely identified by its {@link #mediaType()}, and 
has a
+ * suggested {@link #fileExtension()}.
+ * 
+ * Some of the RDF syntaxes may {@link #supportsDataset()}, meaning they 
can
+ * represent {@link Quad}s.
+ * 
+ * An enumeration of the official RDF 1.1 syntaxes is available in 
+ * {@link OfficialRDFSyntax} - for convenience they are also accessible
+ * as constants here, e.g. RDFSyntax.JSONLD.
+ * 
+ */
+public interface RDFSyntax {
+ 
+public static OfficialRDFSyntax JSONLD = OfficialRDFSyntax.JSONLD;
+public static OfficialRDFSyntax TURTLE = OfficialRDFSyntax.TURTLE;
+public static OfficialRDFSyntax NQUADS = OfficialRDFSyntax.NQUADS;
+public static OfficialRDFSyntax NTRIPLES = OfficialRDFSyntax.NTRIPLES;
+public static OfficialRDFSyntax RDFA_HTML = 
OfficialRDFSyntax.RDFA_HTML;
+public static OfficialRDFSyntax RDFA_XHTML = 
OfficialRDFSyntax.RDFA_XHTML;
+public static OfficialRDFSyntax RDFXML = OfficialRDFSyntax.RDFXML;
+public static OfficialRDFSyntax TRIG = OfficialRDFSyntax.TRIG;
+
+/**
+ * A short name of the RDF Syntax.
+ * 
+ * The name typically corresponds to the {@link Enum#name()} of for
+ * {@link OfficialRDFSyntax}, e.g. JSONLD.
+ * 
+ * @return Short name for RDF syntax
+ */
+public String name();
+
+/**
+ * The title of the RDF Syntax.
+ * 
+ * This is generally the title of the corresponding standard, 
+ * e.g. RDF 1.1 Turtle.
+ * 
+ * @return Title of RDF Syntax
+ */
+public String title();
+
+/**
+ * The https://tools.ietf.org/html/rfc2046;>IANA media 
type for
+ * the RDF syntax.
+ * 
+ * The media type can be used as part of Content-Type and
+ * Accept for content negotiation in the
+ * https://tools.ietf.org/html/rfc7231#section-3.1.1.1;>HTTP
+ * protocol.
+ */
+public String mediaType();
--- End diff --

No, only the official media type and extension should be used in this 
interface - however subtypes might add `mediaTypes()` and similar, or list 
several `RDFSyntax` instances (which would then not be `.equal()`).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org