You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ki...@apache.org on 2018/12/29 21:52:37 UTC
[jena] 02/03: JENA-204: add option 'lang' to schemagen to specify
language to retrieve comments
This is an automated email from the ASF dual-hosted git repository.
kinow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jena.git
commit cf8691c3dfa8b64ae332ee405e6bb8ce357921a8
Author: Bruno P. Kinoshita <ki...@apache.org>
AuthorDate: Sat Dec 29 19:46:43 2018 +1300
JENA-204: add option 'lang' to schemagen to specify language to retrieve comments
---
jena-cmds/src/main/java/jena/schemagen.java | 31 ++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/jena-cmds/src/main/java/jena/schemagen.java b/jena-cmds/src/main/java/jena/schemagen.java
index 4ac22da..05715b7 100644
--- a/jena-cmds/src/main/java/jena/schemagen.java
+++ b/jena-cmds/src/main/java/jena/schemagen.java
@@ -125,6 +125,9 @@ public class schemagen {
/** The output stream we write to */
protected PrintStream m_output;
+ /** The language used to retrieve comments */
+ protected String m_lang;
+
/** Option definitions */
/** Stack of replacements to apply */
protected List<Replacement> m_replacements = new ArrayList<>();
@@ -197,6 +200,7 @@ public class schemagen {
addIncludes();
determineLanguage();
selectInput();
+ selectLang();
selectOutput();
setGlobalReplacements();
@@ -267,6 +271,14 @@ public class schemagen {
}
}
+ protected void selectLang() {
+ if (m_options.hasLangOption()) {
+ m_lang = m_options.getLangOption();
+ } else {
+ m_lang = null;
+ }
+ }
+
/** Identify the file we are to write the output to */
protected void selectOutput() {
String outFile = m_options.getOutputOption();
@@ -405,6 +417,7 @@ public class schemagen {
System.err.println();
System.err.println( "Commonly used options include:" );
System.err.println( " -i <input> the source document as a file or URL." );
+ System.err.println( " -l <lang> the desired language to use to retrieve comments." );
System.err.println( " -n <name> the name of the created Java class." );
System.err.println( " -a <uri> the namespace URI of the source document." );
System.err.println( " -o <file> the file to write the generated class into." );
@@ -1165,7 +1178,13 @@ public class schemagen {
for (NodeIterator ni = m_source.listObjectsOfProperty( r, RDFS.comment ); ni.hasNext(); ) {
RDFNode n = ni.nextNode();
if (n instanceof Literal) {
- comment.append( ((Literal) n).getLexicalForm().trim() );
+ if (m_lang == null || m_lang.trim().equals("")) {
+ // default behavior, where no language was specified
+ comment.append( ((Literal) n).getLexicalForm().trim() );
+ } else if (((Literal) n).getLanguage().equals(m_lang)) {
+ // otherwise only use comment that matches the language given
+ comment.append( ((Literal) n).getLexicalForm().trim() );
+ }
}
else {
System.err.println( "Warning: Comment on resource <" + r.getURI() + "> is not a literal: " + n );
@@ -1408,6 +1427,9 @@ public class schemagen {
/** Nominate the URL of the input document; use <code>-i <URL></code> on command line; use <code>sgen:input</code> in config file */
INPUT,
+ /** Specify the language used to retrieve comments */
+ LANG,
+
/** Specify that the language of the source is DAML+OIL; use <code>--daml</code> on command line; use <code>sgen:daml</code> in config file */
LANG_DAML,
@@ -1526,6 +1548,7 @@ public class schemagen {
{OPT.ROOT, new OptionDefinition( "-r", "root" ) },
{OPT.NO_COMMENTS, new OptionDefinition( "--nocomments", "noComments" ) },
{OPT.INPUT, new OptionDefinition( "-i", "input" ) },
+ {OPT.LANG, new OptionDefinition( "-l", "lang" ) },
{OPT.LANG_DAML, new OptionDefinition( "--daml", "daml" ) },
{OPT.LANG_OWL, new OptionDefinition( "--owl", "owl" ) },
{OPT.LANG_RDFS, new OptionDefinition( "--rdfs", "rdfs" ) },
@@ -1572,6 +1595,8 @@ public class schemagen {
public String getNoCommentsOption();
public boolean hasInputOption();
public Resource getInputOption();
+ public boolean hasLangOption();
+ public String getLangOption();
public boolean hasLangOwlOption();
public String getLangOwlOption();
public boolean hasLangRdfsOption();
@@ -1803,6 +1828,10 @@ public class schemagen {
@Override
public Resource getInputOption() { return getResource( OPT.INPUT ); }
@Override
+ public boolean hasLangOption() { return hasValue( OPT.LANG ); }
+ @Override
+ public String getLangOption() { return getStringValue( OPT.LANG ); }
+ @Override
public boolean hasLangOwlOption() { return isTrue( OPT.LANG_OWL ); }
@Override
public String getLangOwlOption() { return getStringValue( OPT.LANG_OWL ); }