/** Add the bindings in the prefixToURI to our own. This will fail with a ClassCastException if any key or value is not a String; we make no guarantees about order or completeness if this happens. It will fail with an IllegalPrefixException if any prefix is illegal; similar provisos apply. @param other the Map whose bindings we are to add to this. */ @Override public PrefixMapping setNsPrefixes( Map<String, String> other ) { checkUnlocked(); for (Entry<String, String> e: other.entrySet()) setNsPrefix( e.getKey(), e.getValue() ); return this; }
private QueryExecution createQueryExecution(Query query, Model model) { QueryExecution result = QueryExecutionFactory.create(query, model); PrefixMappingImpl prefixes = new PrefixMappingImpl(); prefixes.setNsPrefixes(tq.getPrologue().getPrefixMapping()); prefixes.setNsPrefix("tarql", tarql.NS); result.getContext().set(ExpandPrefixFunction.PREFIX_MAPPING, prefixes); return result; }
/** Add the bindings in the prefixToURI to our own. This will fail with a ClassCastException if any key or value is not a String; we make no guarantees about order or completeness if this happens. It will fail with an IllegalPrefixException if any prefix is illegal; similar provisos apply. @param other the Map whose bindings we are to add to this. */ @Override public PrefixMapping setNsPrefixes( Map<String, String> other ) { checkUnlocked(); for (Entry<String, String> e: other.entrySet()) setNsPrefix( e.getKey(), e.getValue() ); return this; }
/** Answer this PrefixMapping after updating it with the <code>(p, u)</code> mappings in <code>other</code> where neither <code>p</code> nor <code>u</code> appear in this mapping. */ @Override public PrefixMapping withDefaultMappings( PrefixMapping other ) { checkUnlocked(); for (Entry<String, String> e: other.getNsPrefixMap().entrySet()) { String prefix = e.getKey(), uri = e.getValue(); if (getNsPrefixURI( prefix ) == null && getNsURIPrefix( uri ) == null) setNsPrefix( prefix, uri ); } return this; }
/** Answer this PrefixMapping after updating it with the <code>(p, u)</code> mappings in <code>other</code> where neither <code>p</code> nor <code>u</code> appear in this mapping. */ @Override public PrefixMapping withDefaultMappings( PrefixMapping other ) { checkUnlocked(); for (Entry<String, String> e: other.getNsPrefixMap().entrySet()) { String prefix = e.getKey(), uri = e.getValue(); if (getNsPrefixURI( prefix ) == null && getNsURIPrefix( uri ) == null) setNsPrefix( prefix, uri ); } return this; }
@Override public SecuredPrefixMapping withDefaultMappings(final PrefixMapping map) throws UpdateDeniedException, AuthenticationRequiredException { // mapping only updates if there are map entries to add. Since this gets // called // when we are doing deep triple checks while writing we need to attempt // the // update only if there are new updates to add. PrefixMapping m = holder.getBaseItem(); PrefixMappingImpl pm = new PrefixMappingImpl(); for (Entry<String, String> e : map.getNsPrefixMap().entrySet()) { if (m.getNsPrefixURI(e.getKey()) == null && m.getNsURIPrefix(e.getValue()) == null) { pm.setNsPrefix(e.getKey(), e.getValue()); } } if (!pm.getNsPrefixMap().isEmpty()) { checkUpdate(); holder.getBaseItem().withDefaultMappings(pm); } return holder.getSecuredItem(); } }
public static Model toModel(BsbmResult stats) { Model result; try { result = ModelFactory.createDefaultModel(); EntityManager em = new SparqlEntityManagerFactory() .setPrefixMapping(new PrefixMappingImpl() .setNsPrefix("schema", "http://schema.org/") .setNsPrefix("dbo", "http://dbpedia.org/ontology/") .setNsPrefix("dbr", "http://dbpedia.org/resource/") .setNsPrefix("bsbm", "http://bsbm.org/")) .addScanPackageName(BsbmResult.class.getPackage().getName()) .setSparqlService(FluentSparqlService.from(result).create()) .getObject(); em.persist(stats); } catch(Exception e) { throw new RuntimeException(e); } return result; } }
@Test public void test_param_string_constructor_9() { // Test constructors with predefined prefixes - variant of constructor // that does not require command text PrefixMappingImpl prefixes = new PrefixMappingImpl(); prefixes.setNsPrefix("ex", "http://example.org"); ParameterizedSparqlString query = new ParameterizedSparqlString(prefixes); Assert.assertEquals(prefixes.getNsPrefixURI("ex"), query.getNsPrefixURI("ex")); }
@Test public void test_param_string_constructor_8() { // Test constructors with predefined prefixes PrefixMappingImpl prefixes = new PrefixMappingImpl(); prefixes.setNsPrefix("ex", "http://example.org"); ParameterizedSparqlString query = new ParameterizedSparqlString("", prefixes); Assert.assertEquals(prefixes.getNsPrefixURI("ex"), query.getNsPrefixURI("ex")); }