Search in sources :

Example 1 with UrisScheme

use of org.wikidata.query.rdf.common.uri.UrisScheme in project wikidata-query-rdf by wikimedia.

the class StreamingUpdate method build.

static StreamingUpdaterConsumer build(StreamingUpdateOptions options, MetricRegistry metrics) {
    RDFChunkDeserializer deser = new RDFChunkDeserializer(new RDFParserSuppliers(RDFParserRegistry.getInstance()));
    KafkaStreamConsumer consumer = KafkaStreamConsumer.build(options.brokers(), options.topic(), options.partition(), options.consumerGroup(), options.batchSize(), deser, parseInitialOffset(options), KafkaStreamConsumerMetricsListener.forRegistry(metrics), options.bufferedInputMessages(), buildFilter(StreamingUpdateOptions.entityFilterPattern(options)));
    HttpClient httpClient = buildHttpClient(getHttpProxyHost(), getHttpProxyPort());
    Retryer<ContentResponse> retryer = buildHttpClientRetryer();
    Duration rdfClientTimeout = RdfRepositoryUpdater.getRdfClientTimeout();
    RdfClient rdfClient = new RdfClient(httpClient, StreamingUpdateOptions.sparqlUri(options), retryer, rdfClientTimeout);
    UrisScheme uris = UrisSchemeFactory.getURISystem();
    return new StreamingUpdaterConsumer(consumer, new RdfRepositoryUpdater(rdfClient, uris), metrics, options.inconsistenciesWarningThreshold());
}
Also used : RDFParserSuppliers(org.wikidata.query.rdf.tool.rdf.RDFParserSuppliers) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) UrisScheme(org.wikidata.query.rdf.common.uri.UrisScheme) HttpClient(org.eclipse.jetty.client.HttpClient) HttpClientUtils.buildHttpClient(org.wikidata.query.rdf.tool.HttpClientUtils.buildHttpClient) RdfRepositoryUpdater(org.wikidata.query.rdf.tool.rdf.RdfRepositoryUpdater) Duration(java.time.Duration) RdfClient(org.wikidata.query.rdf.tool.rdf.client.RdfClient) RDFChunkDeserializer(org.wikidata.query.rdf.updater.RDFChunkDeserializer)

Example 2 with UrisScheme

use of org.wikidata.query.rdf.common.uri.UrisScheme in project wikidata-query-rdf by wikimedia.

the class DefaultUrisSchemeUnitTest method testBNodeSkolemIRIPrefix.

@Test
public void testBNodeSkolemIRIPrefix() throws URISyntaxException {
    UrisScheme uris = new DefaultUrisScheme(new URI("http://acme2.test"), WIKIBASE_ENTITY_PREFIX, WIKIBASE_ENTITY_DATA_PREFIX, WIKIBASE_INITIALS);
    assertThat(uris.wellKnownBNodeIRIPrefix()).isEqualTo("http://acme2.test/.well-known/genid/");
}
Also used : UrisScheme(org.wikidata.query.rdf.common.uri.UrisScheme) DefaultUrisScheme(org.wikidata.query.rdf.common.uri.DefaultUrisScheme) DefaultUrisScheme(org.wikidata.query.rdf.common.uri.DefaultUrisScheme) URI(java.net.URI) Test(org.junit.Test)

Example 3 with UrisScheme

use of org.wikidata.query.rdf.common.uri.UrisScheme in project wikidata-query-rdf by wikimedia.

the class DefaultUrisSchemeUnitTest method conceptUri.

@Test
public void conceptUri() throws URISyntaxException {
    UrisScheme uris = new DefaultUrisScheme(new URI("http://acme.test/prefix"), WIKIBASE_ENTITY_PREFIX, WIKIBASE_ENTITY_DATA_PREFIX, WIKIBASE_INITIALS);
    assertThat(uris.entityURIs()).contains("http://acme.test/prefix/entity/");
    assertThat(uris.entityIdToURI("Q1")).isEqualTo("http://acme.test/prefix/entity/Q1");
    assertThat(uris.entityIdToURI("P1")).isEqualTo("http://acme.test/prefix/entity/P1");
    assertThat(uris.entityData()).isEqualTo("http://acme.test/prefix/wiki/Special:EntityData/");
    assertThat(uris.entityDataHttps()).isEqualTo("https://acme.test/prefix/wiki/Special:EntityData/");
}
Also used : UrisScheme(org.wikidata.query.rdf.common.uri.UrisScheme) DefaultUrisScheme(org.wikidata.query.rdf.common.uri.DefaultUrisScheme) DefaultUrisScheme(org.wikidata.query.rdf.common.uri.DefaultUrisScheme) URI(java.net.URI) Test(org.junit.Test)

Example 4 with UrisScheme

use of org.wikidata.query.rdf.common.uri.UrisScheme in project wikidata-query-rdf by wikimedia.

the class DefaultUrisSchemeUnitTest method conceptUriSlash.

@Test
public void conceptUriSlash() throws URISyntaxException {
    UrisScheme uris = new DefaultUrisScheme(new URI("http://acme3.test/"), WIKIBASE_ENTITY_PREFIX, WIKIBASE_ENTITY_DATA_PREFIX, WIKIBASE_INITIALS);
    assertThat(uris.entityURIs()).contains("http://acme3.test/entity/");
    assertThat(uris.entityIdToURI("Q1")).isEqualTo("http://acme3.test/entity/Q1");
    assertThat(uris.entityIdToURI("P1")).isEqualTo("http://acme3.test/entity/P1");
    assertThat(uris.entityData()).isEqualTo("http://acme3.test/wiki/Special:EntityData/");
    assertThat(uris.entityDataHttps()).isEqualTo("https://acme3.test/wiki/Special:EntityData/");
}
Also used : UrisScheme(org.wikidata.query.rdf.common.uri.UrisScheme) DefaultUrisScheme(org.wikidata.query.rdf.common.uri.DefaultUrisScheme) DefaultUrisScheme(org.wikidata.query.rdf.common.uri.DefaultUrisScheme) URI(java.net.URI) Test(org.junit.Test)

Example 5 with UrisScheme

use of org.wikidata.query.rdf.common.uri.UrisScheme in project wikidata-query-rdf by wikimedia.

the class EntityMungingRdfHandlerUnitTest method testSmallDump.

@Test
public void testSmallDump() throws RDFParseException, IOException, RDFHandlerException {
    UrisScheme uriScheme = UrisSchemeFactory.WIKIDATA;
    Munger munger = Munger.builder(uriScheme).build();
    RDFHandler childHandler = mock(RDFHandler.class);
    AtomicLong nbEntities = new AtomicLong();
    EntityMungingRdfHandler handler = new EntityMungingRdfHandler(uriScheme, munger, childHandler, nbEntities::set);
    RDFParser parser = Rio.createParser(RDFFormat.TURTLE);
    parser.setRDFHandler(handler);
    parser.parse(this.getClass().getResourceAsStream("small_dump.ttl"), uriScheme.root());
    verify(childHandler, atLeastOnce()).handleStatement(statements.capture());
    assertThat(munger.getDumpFormatVersion()).isEqualTo("1.0.0");
    assertThat(statements.getAllValues()).contains(// initial Dump statements are kept and passsed through
    statement("http://wikiba.se/ontology#Dump", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://schema.org/Dataset"), // a random statement
    statement("https://en.wikipedia.org/wiki/Resource_Description_Framework", "http://schema.org/about", "http://www.wikidata.org/entity/Q54872"), statement("http://www.wikidata.org/entity/Q6825", "http://www.w3.org/2002/07/owl#sameAs", "http://www.wikidata.org/entity/Q26709563"), // redirect revision ID
    statement("http://www.wikidata.org/entity/Q6825", "http://schema.org/version", 942411738), statement("https://it.wikivoyage.org/wiki/Belgio", "http://schema.org/about", "http://www.wikidata.org/entity/Q31"));
    // Check that the blank node is kept
    assertThat(statements.getAllValues()).filteredOn(s -> s.getSubject().stringValue().equals("http://www.wikidata.org/entity/Q54872") && s.getPredicate().stringValue().equals("http://www.wikidata.org/prop/direct/P576")).size().isEqualTo(1);
    assertThat(nbEntities.intValue()).isEqualTo(3);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) UrisScheme(org.wikidata.query.rdf.common.uri.UrisScheme) RDFParser(org.openrdf.rio.RDFParser) RDFHandler(org.openrdf.rio.RDFHandler) Test(org.junit.Test)

Aggregations

UrisScheme (org.wikidata.query.rdf.common.uri.UrisScheme)14 Test (org.junit.Test)9 DefaultUrisScheme (org.wikidata.query.rdf.common.uri.DefaultUrisScheme)7 URI (java.net.URI)6 MetricRegistry (com.codahale.metrics.MetricRegistry)3 IOException (java.io.IOException)2 Duration (java.time.Duration)2 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 HttpClient (org.eclipse.jetty.client.HttpClient)2 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)2 RDFHandler (org.openrdf.rio.RDFHandler)2 HttpClientUtils.buildHttpClient (org.wikidata.query.rdf.tool.HttpClientUtils.buildHttpClient)2 Change (org.wikidata.query.rdf.tool.change.Change)2 Munger (org.wikidata.query.rdf.tool.rdf.Munger)2 RdfClient (org.wikidata.query.rdf.tool.rdf.client.RdfClient)2 FunctionRegistry (com.bigdata.rdf.sparql.ast.FunctionRegistry)1 RemoteServiceFactoryImpl (com.bigdata.rdf.sparql.ast.service.RemoteServiceFactoryImpl)1 ServiceRegistry (com.bigdata.rdf.sparql.ast.service.ServiceRegistry)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1