@Override public RyaType newInstance() { return new RyaURI(); } }
private static Set<RyaURI> getPropURIFromStrings(final String... props) { final Set<RyaURI> properties = new HashSet<>(); if (props != null) { for(final String prop : props) { if (StringUtils.isNotBlank(prop)) { properties.add(new RyaURI(prop)); } } } return properties; }
static void setUpRya() throws AccumuloException, AccumuloSecurityException, RyaDAOException { MockInstance mock = new MockInstance(INSTANCE_NAME); Connector conn = mock.getConnector(USERNAME, new PasswordToken(USERP)); AccumuloRyaDAO dao = new AccumuloRyaDAO(); dao.setConnector(conn); AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); conf.setTablePrefix(PREFIX); dao.setConf(conf); dao.init(); String ns = "http://example.com/"; dao.add(new RyaStatement(new RyaURI(ns+"s1"), new RyaURI(ns+"p1"), new RyaURI(ns+"o1"))); dao.add(new RyaStatement(new RyaURI(ns+"s1"), new RyaURI(ns+"p2"), new RyaURI(ns+"o2"))); dao.add(new RyaStatement(new RyaURI(ns+"s2"), new RyaURI(ns+"p1"), new RyaURI(ns+"o3"), new RyaURI(ns+"g1"))); dao.add(new RyaStatement(new RyaURI(ns+"s3"), new RyaURI(ns+"p3"), new RyaURI(ns+"o3"), new RyaURI(ns+"g2"))); dao.destroy(); }
public Set<RyaURI> getStatementMetadataProperties() { final Set<RyaURI> uriSet = new HashSet<>(); final String[] uriStrings = getStrings(CONF_STATEMENT_METADATA_PROPERTIES); if (uriStrings != null) { for (final String s : uriStrings) { uriSet.add(new RyaURI(s)); } } return uriSet; }
public static RyaURI findSubject(final String uriString) throws SmartUriException { java.net.URI uri; try { uri = new java.net.URI(uriString); } catch (final URISyntaxException e) { throw new SmartUriException("Could not find subject in Smart URI", e); } final RyaURI subject; final String fullFragment = uri.getFragment(); if (fullFragment != null) { final int queryPosition = fullFragment.indexOf("?"); String partialFragment = null; if (queryPosition != - 1) { partialFragment = fullFragment.substring(0, queryPosition); } final String subjectString = uri.getScheme() + ":" + uri.getSchemeSpecificPart() + "#" + partialFragment; subject = new RyaURI(subjectString); } else { final int queryPosition = uriString.indexOf("?"); String subjectString = null; if (queryPosition != - 1) { subjectString = uriString.substring(0, queryPosition); } else { subjectString = uriString; } subject = new RyaURI(subjectString); } return subject; }
@Override public RyaType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String type = jsonObject.get("type").getAsString(); JsonElement element = jsonObject.get("properties"); String[] array = element.getAsJsonPrimitive().getAsString().split("\u0000"); Preconditions.checkArgument(array.length == 2); if(type.equals(RyaURI.class.getName())){ return new RyaURI(array[0]); } else if(type.equals(RyaType.class.getName())){ RyaType ryaType = new RyaType(new URIImpl(array[1]), array[0]); return ryaType; } else { throw new IllegalArgumentException("Unparseable RyaType."); } } }
private static Map<RyaURI, String> convertUriToTypeMap(final URI typeMapUri) throws SmartUriException { final Map<RyaURI, String> map = new HashMap<>(); java.net.URI uri; try { final URIBuilder uriBuilder = new URIBuilder(typeMapUri.stringValue()); uri = uriBuilder.build(); } catch (final URISyntaxException e) { throw new SmartUriException("Unable to parse Rya type map in Smart URI", e); } final List<NameValuePair> params = URLEncodedUtils.parse(uri, Charsets.UTF_8.name()); for (final NameValuePair param : params) { final String name = param.getName(); final String value = param.getValue(); final RyaURI type = new RyaURI(name); map.put(type, value); } return map; }
public static RyaURI convertResource(Resource subject) { if(subject == null) return null; if (subject instanceof BNode) { return new RyaURI(RyaSchema.BNODE_NAMESPACE + ((BNode) subject).getID()); } return convertURI((URI) subject); }
/** * Converts a {@link Map} of {@link URI}/{@link Value}s to a {@link Set} of * {@link Property}s. * @param map the {@link Map} of {@link URI}/{@link Value}. * @return the {@link Set} of {@link Property}s. */ public static Set<Property> mapToProperties(final Map<URI, Value> map) { final Set<Property> properties = new LinkedHashSet<>(); for (final Entry<URI, Value> entry : map.entrySet()) { final URI uri = entry.getKey(); final Value value = entry.getValue(); final RyaURI ryaUri = new RyaURI(uri.stringValue()); final RyaType ryaType = RdfToRyaConversions.convertValue(value); final Property property = new Property(ryaUri, ryaType); properties.add(property); } return properties; }
@Override public Type fromDocument(final Document document) throws DocumentConverterException { requireNonNull(document); if(!document.containsKey(ID)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + ID + "' field is missing."); } if(!document.containsKey(PROPERTY_NAMES)) { throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + PROPERTY_NAMES + "' field is missing."); } final RyaURI typeId = new RyaURI( document.getString(ID) ); final ImmutableSet.Builder<RyaURI> propertyNames = ImmutableSet.builder(); ((List<String>) document.get(PROPERTY_NAMES)) .forEach(propertyName -> propertyNames.add(new RyaURI(propertyName))); return new Type(typeId, propertyNames.build()); } }
private RyaURI getPredURI(final StatementPattern pattern) { final Var pred = pattern.getPredicateVar(); return new RyaURI(pred.getValue().stringValue()); }
/** * Verify all of the patterns have predicates that match one of the Type's property names. * * @param type - The Type the patterns match. (not null) * @param patterns - The patterns to check. * @throws IllegalStateException If any of the non-type defining Statement Patterns * contain a predicate that does not match one of the Type's property names. */ private static void verifyAllPredicatesPartOfType(final Type type, final Collection<StatementPattern> patterns) throws IllegalStateException { requireNonNull(type); requireNonNull(patterns); for(final StatementPattern pattern : patterns) { // Skip TYPE patterns. final RyaURI predicate = new RyaURI( pattern.getPredicateVar().getValue().toString() ); if(predicate.equals(TYPE_ID_URI)) { continue; } if(!type.getPropertyNames().contains(predicate)) { throw new IllegalStateException("The Predicate of a Statement Pattern must be a property name for the Type. " + "Type ID: '" + type.getId().getData() + "' Pattern: " + pattern); } } }
private static Entity convertMapToEntity(final RyaURI subject, final Map<RyaURI, Map<URI, Value>> map) { final Entity.Builder entityBuilder = Entity.builder(); entityBuilder.setSubject(subject); for (final Entry<RyaURI, Map<URI, Value>> typeEntry : map.entrySet()) { final RyaURI type = typeEntry.getKey(); final Map<URI, Value> subMap = typeEntry.getValue(); entityBuilder.setExplicitType(type); for (final Entry<URI, Value> entry : subMap.entrySet()) { final URI uri = entry.getKey(); final Value value = entry.getValue(); final RyaURI ryaUri = new RyaURI(uri.stringValue()); final RyaURI ryaName = new RyaURI(uri.stringValue()); final RyaType ryaType = new RyaType(value.stringValue()); final Property property = new Property(ryaName, ryaType); entityBuilder.setProperty(ryaUri, property); } } final Entity entity = entityBuilder.build(); return entity; }
/** * Verifies a single Statement Pattern defines the Type of Entity this query node matches. * * @param type - The expected Type. (not null) * @param patterns - The patterns to check. (not null) * @throws IllegalStateException No Type or the wrong Type is specified by the patterns. */ private static void verifyHasCorrectTypePattern(final Type type, final Collection<StatementPattern> patterns) throws IllegalStateException { requireNonNull(type); requireNonNull(patterns); boolean typeFound = false; for(final StatementPattern pattern : patterns) { final RyaURI predicate = new RyaURI(pattern.getPredicateVar().getValue().toString()); if(predicate.equals(TYPE_ID_URI)) { final RyaURI typeId = new RyaURI( pattern.getObjectVar().getValue().stringValue() ); if(typeId.equals(type.getId())) { typeFound = true; } else { throw new IllegalStateException("Statement Pattern encountred for a Type that does not match the expected Type." + " Expected Type = '" + type.getId().getData() + "' Found Type = '" + typeId.getData() + "'"); } } } if(!typeFound) { throw new IllegalStateException("The collection of Statement Patterns that this node matches must define which Type they match."); } }
final Var object = sp.getObjectVar(); final Var pred = sp.getPredicateVar(); final RyaURI predURI = new RyaURI(pred.getValue().stringValue()); bindingNames.addAll(sp.getBindingNames()); if(object.isConstant() && !pred.getValue().equals(RDF.TYPE)) {
break; case OBJECT: subject = new RyaURI(new String(entityBytes, StandardCharsets.UTF_8)); type = subject; break;
public static RyaURI convertURI(URI uri) { if (uri == null) return null; if (uri instanceof RangeURI) { RangeURI ruri = (RangeURI) uri; return new RyaURIRange(convertURI(ruri.getStart()), convertURI(ruri.getEnd())); } return new RyaURI(uri.stringValue()); }
RyaType value; if (objectType.equals(XMLSchema.ANYURI.toString())){ value = new RyaURI(objectValue); RyaStatement statement = new RyaStatement(new RyaURI(subject), new RyaURI(predicate), value); int length = 0; boolean hasNextValue = input.readBoolean(); if (hasNextValue){ statement.setContext(new RyaURI(input.readString()));
final RyaURI predicate = new RyaURI(pattern.getPredicateVar().getValue().toString());