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

Literal.java update #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README_BUILD.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build using:
mvn -Dmaven.test.skip=true -U clean package
to skip tests
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
<!-- workaround for http://jira.codehaus.org/browse/MRESOURCES-99 -->
<buildDate>${maven.build.timestamp}</buildDate>
</properties>

<repositories>
<repository>
<id>codelds</id>
<url>https://maven.nuxeo.org/nexus/content/groups/public/</url>
</repository>
</repositories>


<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -530,4 +538,4 @@
</build>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ private void startNextQuery() throws SQLException {
_statement.setFetchSize(_fetchSize);
_statement.setFetchDirection(ResultSet.FETCH_FORWARD);
String query = _queries.next();
LOG.info("Executing query:\n" + query);
LOG.debug("Executing query:\n" + query);
_results = _statement.executeQuery(query);
} else {
LOG.info("Finished executing all queries");
LOG.debug("Finished executing all queries");
close(); // proactively close if no more queries
_results = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,12 +891,12 @@ public MPTable mapPredicateTable(
if (tableName == null) {
/* No predicate found.. create table that returns no results */
alias = "np_" + nonexistantMappings.size();
tableName = "(SELECT p AS s, p AS o from tmap where 1=0)";
tableName = "(SELECT p AS s, p AS o from tMap where 1=0)";
if (!nonexistantMappings.containsKey(predicate.getNode())) {
alias = "np_" + nonexistantMappings.size();
LOG.debug("No table for '" + predicate.getNode()
+ "'. Using empty table as " + alias);
tableName = "(SELECT p AS s, p AS o from tmap where 1=0)";
tableName = "(SELECT p AS s, p AS o from tMap where 1=0)";
nonexistantMappings.put(predicate.getNode(), new MPTable(
tableName, alias));
predicateMap.put(predicate.getNode().toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void addSelect(final PredicateNode predicate) {
}

String sqlString = select.toString();
LOG.info("Generated query:\n" + sqlString);
LOG.debug("Generated query:\n" + sqlString);
_sql.add(sqlString);
}
}
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/org/nsdl/mptstore/rdf/Literal.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
* @see <a href="http://www.w3.org/TR/rdf-concepts/#section-Graph-Literal">
* RDF Concepts and Abstract Syntax, Section 6.5</a>
*/
public class Literal implements ObjectNode {
public class Literal implements ObjectNode {

public static final int LITERAL_MAXLEN = 255;

/**
* The lexical value of this literal.
*/
Expand Down Expand Up @@ -100,13 +102,31 @@ public String getValue() {
public String toString() {
StringBuffer out = new StringBuffer();
out.append('"');
out.append(NTriplesUtil.escapeLiteralValue(_value));

// 5 is the length of "" and ...
int suffixLenght = 5;
if(_language != null){
// it might be 2 or 3 letter code
suffixLenght += 1 + _language.length();
}
if(_datatype != null){
suffixLenght += 2 + _datatype.toString().length();
}

int stringMaxLenght = 0;
if(LITERAL_MAXLEN > 0){
stringMaxLenght = LITERAL_MAXLEN-suffixLenght;
}

out.append(NTriplesUtil.escapeAndTruncateLiteralValue(_value, stringMaxLenght));

out.append('"');
if (_language != null) {
out.append("@" + _language);
} else if (_datatype != null) {
out.append("^^" + _datatype.toString());
}

return out.toString();
}

Expand Down
41 changes: 26 additions & 15 deletions src/main/java/org/nsdl/mptstore/util/NTriplesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class NTriplesUtil {
* Maximum characters for a language code subtag.
*/
private static final int SUBTAG_MAXLEN = 8;

private static final int HIGHEST_ASCII_CHAR = 127;
private static final int HEX = 16;
private static final int SHORT_ESCAPE_LENGTH = 5;
Expand Down Expand Up @@ -634,32 +634,43 @@ public static String unescapeLiteralValue(final String s)
* @param s The input string.
* @return The escaped string.
*/
public static String escapeLiteralValue(final String s) {
public static String escapeAndTruncateLiteralValue(final String s, final int stringMaxLenght) {

int len = s.length();
StringBuffer out = new StringBuffer(len * 2);

StringBuffer out = new StringBuffer(len * 2);
for (int i = 0; i < len; i++) {

if(stringMaxLenght > 0 && (out.length() == stringMaxLenght)){
return out.toString() + "...";
}

String app = "";
char c = s.charAt(i);
int cNum = (int) c;
if (c == '\\') {
out.append("\\\\");
app = "\\\\";
} else if (c == '"') {
out.append("\\\"");
app = "\\\"";
} else if (c == '\n') {
out.append("\\n");
app = "\\n";
} else if (c == '\r') {
out.append("\\r");
app = "\\r";
} else if (c == '\t') {
out.append("\\t");
app = "\\t";
} else if (isLowUnicode(cNum)) {
out.append("\\u");
out.append(hexString(cNum, SHORT_ESCAPE_LENGTH - 1));
app = "\\u" + hexString(cNum, SHORT_ESCAPE_LENGTH - 1);
} else if (isHighUnicode(cNum)) {
out.append("\\U");
out.append(hexString(cNum, LONG_ESCAPE_LENGTH - 2));
} else {
out.append(c);
app = "\\U" + hexString(cNum, LONG_ESCAPE_LENGTH - 2);
} else {
out.append(c);
continue;
}

if(stringMaxLenght > 0 && (out.length() + app.length() > stringMaxLenght)){
return out.toString() + "...";
}else{
out.append(app);
}
}

Expand Down