You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by og...@apache.org on 2012/03/24 15:31:39 UTC
svn commit: r1304811 - in /incubator/stanbol/trunk/enhancer/engines/topic:
./ src/main/java/org/apache/stanbol/enhancer/engine/topic/
src/main/java/org/apache/stanbol/enhancer/topic/
src/main/java/org/apache/stanbol/enhancer/topic/training/ src/main/re...
Author: ogrisel
Date: Sat Mar 24 14:31:38 2012
New Revision: 1304811
URL: http://svn.apache.org/viewvc?rev=1304811&view=rev
Log:
STANBOL-197: refactored solr setup to make it possible use empty default config with OSGi
Added:
incubator/stanbol/trunk/enhancer/engines/topic/build-archives.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-model/
- copied from r1303447, incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/classifier/
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-model/conf/
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-model/conf/schema.xml
- copied unchanged from r1303447, incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/classifier/schema.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-model/conf/solrconfig.xml
- copied unchanged from r1303447, incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/classifier/solrconfig.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-trainingset/
- copied from r1303447, incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/trainingset/
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-trainingset/conf/
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-trainingset/conf/schema.xml
- copied unchanged from r1303447, incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/trainingset/schema.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-trainingset/conf/solrconfig.xml
- copied unchanged from r1303447, incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/trainingset/solrconfig.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/solr.xml
Removed:
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/classifier/
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-model/schema.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-model/solr.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-model/solrconfig.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-trainingset/schema.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-trainingset/solr.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/default-topic-trainingset/solrconfig.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/trainingset/
Modified:
incubator/stanbol/trunk/enhancer/engines/topic/pom.xml
incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/engine/topic/TopicClassificationEngine.java
incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/ConfiguredSolrCoreTracker.java
incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/EmbeddedSolrHelper.java
incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/training/SolrTrainingSet.java
incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/ (props changed)
incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TopicEngineTest.java
incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TrainingSetTest.java
Added: incubator/stanbol/trunk/enhancer/engines/topic/build-archives.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/build-archives.xml?rev=1304811&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/build-archives.xml (added)
+++ incubator/stanbol/trunk/enhancer/engines/topic/build-archives.xml Sat Mar 24 14:31:38 2012
@@ -0,0 +1,36 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project name="topic-classifier-solr-archives" default="all" basedir=".">
+
+ <property name="build.directory" value="./src/main/resources/" />
+ <target name="all" depends="model,trainingset" />
+
+ <target name="model">
+ <zip destfile="${build.directory}default-topic-model.solrindex.zip">
+ <zipfileset dir="${build.directory}default-topic-model"
+ prefix="default-topic-model"/>
+ </zip>
+ </target>
+
+ <target name="trainingset">
+ <zip destfile="${build.directory}default-topic-trainingset.solrindex.zip">
+ <zipfileset dir="${build.directory}default-topic-trainingset"
+ prefix="default-topic-trainingset"/>
+ </zip>
+ </target>
+
+</project>
Modified: incubator/stanbol/trunk/enhancer/engines/topic/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/pom.xml?rev=1304811&r1=1304810&r2=1304811&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/pom.xml (original)
+++ incubator/stanbol/trunk/enhancer/engines/topic/pom.xml Sat Mar 24 14:31:38 2012
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
- license agreements. See the NOTICE file distributed with this work for additional
- information regarding copyright ownership. The ASF licenses this file to
- You under the Apache License, Version 2.0 (the "License"); you may not use
- this file except in compliance with the License. You may obtain a copy of
- the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
- by applicable law or agreed to in writing, software distributed under the
- License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
- OF ANY KIND, either express or implied. See the License for the specific
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ You under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@@ -79,12 +79,38 @@
<exclude>src/test/resources/classifier/topics_abstracts_snippet.tsv</exclude>
</excludes>
</configuration>
- </plugin>
+ </plugin>
+ <plugin>
+ <!--
+ Pack the default solr configurations as *.solrindex.zip configs
+ suitable for registration to the DataFileProvider service.
+ -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>compile</id>
+ <phase>compile</phase>
+ <configuration>
+ <target>
+ <property name="build.directory"
+ value="${project.basedir}/src/main/resources/"/>
+ <ant antfile="${basedir}/build-archives.xml">
+ <target name="all"/>
+ </ant>
+ </target>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
<dependencies>
- <!-- Runtime dependencies for testing
+ <!-- Runtime dependencies for testing
WARNING: the testing dependencies should be put first because that has an
impact on the classpath ordering and the OSGi implementation from the test
@@ -132,7 +158,7 @@
<scope>test</scope>
<version>1.3.5</version>
</dependency>
- <!-- The following container should make it possible to run the OSGi
+ <!-- The following container should make it possible to run the OSGi
faster by using felix in the host JVM rather than forking a dedicated JVM. -->
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
@@ -149,7 +175,7 @@
<artifactId>org.apache.felix.scr</artifactId>
<scope>test</scope>
</dependency>
- <!-- The following container can be use instead of native if we want
+ <!-- The following container can be use instead of native if we want
to fork a new JVM and / or test against equinox for instance -->
<!--
<dependency>
Modified: incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/engine/topic/TopicClassificationEngine.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/engine/topic/TopicClassificationEngine.java?rev=1304811&r1=1304810&r2=1304811&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/engine/topic/TopicClassificationEngine.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/engine/topic/TopicClassificationEngine.java Sat Mar 24 14:31:38 2012
@@ -44,6 +44,10 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.ReferenceStrategy;
import org.apache.felix.scr.annotations.Service;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
@@ -57,6 +61,7 @@ import org.apache.solr.common.SolrDocume
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.MoreLikeThisParams;
+import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
import org.apache.stanbol.commons.solr.utils.StreamQueryRequest;
import org.apache.stanbol.enhancer.servicesapi.Blob;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
@@ -109,14 +114,16 @@ import org.slf4j.LoggerFactory;
@Property(name = TopicClassificationEngine.ORDER, intValue = 100),
@Property(name = TopicClassificationEngine.SOLR_CORE),
@Property(name = TopicClassificationEngine.LANGUAGES),
- @Property(name = TopicClassificationEngine.SIMILARTITY_FIELD),
- @Property(name = TopicClassificationEngine.CONCEPT_URI_FIELD),
- @Property(name = TopicClassificationEngine.PRIMARY_TOPIC_URI_FIELD),
- @Property(name = TopicClassificationEngine.BROADER_FIELD),
+ @Property(name = TopicClassificationEngine.SIMILARTITY_FIELD, value = "classifier_features"),
+ @Property(name = TopicClassificationEngine.CONCEPT_URI_FIELD, value = "concept"),
+ @Property(name = TopicClassificationEngine.PRIMARY_TOPIC_URI_FIELD, value = "primary_topic"),
+ @Property(name = TopicClassificationEngine.BROADER_FIELD, value = "broader"),
@Property(name = TopicClassificationEngine.MODEL_UPDATE_DATE_FIELD, value = "last_update_dt"),
@Property(name = TopicClassificationEngine.PRECISION_FIELD, value = "precision"),
@Property(name = TopicClassificationEngine.RECALL_FIELD, value = "recall"),
+ @Property(name = TopicClassificationEngine.ENTRY_ID_FIELD, value = "entry_id"),
@Property(name = TopicClassificationEngine.MODEL_ENTRY_ID_FIELD, value = "model_entry_id"),
+ @Property(name = TopicClassificationEngine.ENTRY_TYPE_FIELD, value = "entry_type"),
@Property(name = TopicClassificationEngine.MODEL_EVALUATION_DATE_FIELD, value = "last_evaluation_dt"),
@Property(name = TopicClassificationEngine.FALSE_NEGATIVES_FIELD, value = "false_negatives"),
@Property(name = TopicClassificationEngine.FALSE_POSITIVES_FIELD, value = "false_positives"),
@@ -244,11 +251,15 @@ public class TopicClassificationEngine e
protected File evaluationFolder;
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, bind = "bindManagedSolrServer", unbind = "unbindManagedSolrServer", strategy = ReferenceStrategy.EVENT, policy = ReferencePolicy.DYNAMIC)
+ protected ManagedSolrServer managedSolrServer;
+
@Activate
protected void activate(ComponentContext context) throws ConfigurationException, InvalidSyntaxException {
@SuppressWarnings("unchecked")
Dictionary<String,Object> config = context.getProperties();
this.context = context;
+ this.indexArchiveName = "default-topic-classifier-model";
configure(config);
}
@@ -293,11 +304,6 @@ public class TopicClassificationEngine e
} else {
return CANNOT_ENHANCE;
}
- // TODO ogrisel: validate that it is no problem that this does no longer
- // check that the text is not empty
- // if (text.trim().length() == 0) {
- // return CANNOT_ENHANCE;
- // }
}
@Override
@@ -418,7 +424,8 @@ public class TopicClassificationEngine e
Float score = (Float) result.getFirstValue("score");
// fetch metadata
- String q = entryTypeField + ":" + METADATA_ENTRY + " AND " + conceptUriField + ":" + ClientUtils.escapeQueryChars(conceptUri);
+ String q = entryTypeField + ":" + METADATA_ENTRY + " AND " + conceptUriField + ":"
+ + ClientUtils.escapeQueryChars(conceptUri);
SolrQuery metadataQuery = new SolrQuery(q);
metadataQuery.setFields(conceptUriField, broaderField, primaryTopicUriField);
SolrDocument metadata = solrServer.query(metadataQuery).getResults().get(0);
@@ -743,7 +750,7 @@ public class TopicClassificationEngine e
* of the model entry id of the topic
* @param impactedTopics
* the list of impacted topics (e.g. the topic node and direct children)
- * @param primaryTopicUri
+ * @param primaryTopicUri
* @param broaderConcepts
* the collection of broader to re-add in the broader field
*/
@@ -865,7 +872,7 @@ public class TopicClassificationEngine e
int updatedTopics = 0;
int cvFoldCount = 3; // 3-folds CV is hardcoded for now
int cvIterationCount = 1; // only one 3-folds CV iteration
-
+
TopicClassificationEngine classifier = new TopicClassificationEngine();
classifier.setTrainingSet(trainingSet);
try {
@@ -889,7 +896,8 @@ public class TopicClassificationEngine e
protected int performCVFold(final TopicClassificationEngine classifier,
int cvFoldIndex,
int cvFoldCount,
- int cvIterations, boolean incremental) throws ConfigurationException,
+ int cvIterations,
+ boolean incremental) throws ConfigurationException,
TrainingSetException,
ClassifierException {
@@ -901,7 +909,7 @@ public class TopicClassificationEngine e
evaluationFolder.mkdir();
try {
EmbeddedSolrServer evaluationServer = EmbeddedSolrHelper.makeEmbeddedSolrServer(evaluationFolder,
- "evaluationclassifierserver", "classifier", "classifier");
+ "evaluationclassifierserver", "default-topic-model", "default-topic-model");
classifier.configure(getCanonicalConfiguration(evaluationServer));
} catch (Exception e) {
throw new ClassifierException(e);
@@ -1167,4 +1175,4 @@ public class TopicClassificationEngine e
}
return sum;
}
-}
+}
\ No newline at end of file
Modified: incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/ConfiguredSolrCoreTracker.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/ConfiguredSolrCoreTracker.java?rev=1304811&r1=1304810&r2=1304811&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/ConfiguredSolrCoreTracker.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/ConfiguredSolrCoreTracker.java Sat Mar 24 14:31:38 2012
@@ -16,6 +16,7 @@
*/
package org.apache.stanbol.enhancer.topic;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
@@ -24,15 +25,19 @@ import java.util.List;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.stanbol.commons.solr.IndexReference;
import org.apache.stanbol.commons.solr.RegisteredSolrServerTracker;
-import org.osgi.framework.InvalidSyntaxException;
+import org.apache.stanbol.commons.solr.managed.IndexMetadata;
+import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.component.ComponentContext;
+import org.xml.sax.SAXException;
/**
* Helper class to factorize some common code for Solr Core tracking OSGi component
*/
public abstract class ConfiguredSolrCoreTracker {
+ protected ManagedSolrServer managedSolrServer;
+
protected String solrCoreId;
protected RegisteredSolrServerTracker indexTracker;
@@ -42,6 +47,8 @@ public abstract class ConfiguredSolrCore
protected ComponentContext context;
+ protected String indexArchiveName;
+
abstract public void configure(Dictionary<String,Object> config) throws ConfigurationException;
protected String getRequiredStringParam(Dictionary<String,Object> parameters, String paramName) throws ConfigurationException {
@@ -80,7 +87,8 @@ public abstract class ConfiguredSolrCore
}
/**
- * @return the manually bound classifierSolrServer instance or the one tracked by the OSGi service tracker.
+ * @return the manually bound classifierSolrServer instance or the one tracked by the OSGi service
+ * tracker.
*/
public SolrServer getActiveSolrServer() {
return solrServer != null ? solrServer : indexTracker.getService();
@@ -99,13 +107,48 @@ public abstract class ConfiguredSolrCore
+ " the engine without any OSGi context. Got: " + solrCoreId);
}
try {
- indexTracker = new RegisteredSolrServerTracker(context.getBundleContext(),
- IndexReference.parse(solrCoreId));
+ IndexReference indexReference = IndexReference.parse(solrCoreId);
+ indexTracker = new RegisteredSolrServerTracker(context.getBundleContext(), indexReference);
indexTracker.open();
- } catch (InvalidSyntaxException e) {
+ this.solrCoreId = solrCoreId;
+
+ // if the solr core is managed, check that the index is properly activated
+ if (managedSolrServer != null
+ && indexReference.checkServer(managedSolrServer.getServerName())) {
+ String indexName = indexReference.getIndex();
+ IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexName);
+ if (indexMetadata == null) {
+ managedSolrServer.createSolrIndex(indexName, indexArchiveName, null);
+ indexMetadata = managedSolrServer.getIndexMetadata(indexName);
+ }
+ if (!indexMetadata.isActive()) {
+ // already managed, but not active yet: do it now
+ managedSolrServer.activateIndex(indexName);
+ }
+ }
+ } catch (Exception e) {
throw new ConfigurationException(solrCoreProperty, e.getMessage(), e);
}
}
}
+ protected void bindManagedSolrServer(ManagedSolrServer managedSolrServer) throws IOException,
+ SAXException {
+ this.managedSolrServer = managedSolrServer;
+ }
+
+ protected void unbindManagedSolrServer(ManagedSolrServer managedSolrServer) {
+ if (this.managedSolrServer == managedSolrServer || solrCoreId != null) {
+ IndexReference indexReference = IndexReference.parse(solrCoreId);
+ if (!indexReference.checkServer(managedSolrServer.getServerName())) {
+ return;
+ }
+ String indexName = indexReference.getIndex();
+ IndexMetadata indexMetadata = managedSolrServer.getIndexMetadata(indexName);
+ if (indexMetadata != null && indexMetadata.isActive()) {
+ managedSolrServer.deactivateIndex(indexName);
+ }
+ this.managedSolrServer = null;
+ }
+ }
}
Modified: incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/EmbeddedSolrHelper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/EmbeddedSolrHelper.java?rev=1304811&r1=1304810&r2=1304811&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/EmbeddedSolrHelper.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/EmbeddedSolrHelper.java Sat Mar 24 14:31:38 2012
@@ -27,6 +27,8 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.CoreDescriptor;
+import org.apache.solr.core.SolrCore;
import org.xml.sax.SAXException;
/**
@@ -50,7 +52,7 @@ public class EmbeddedSolrHelper {
// solr conf file
File solrFile = new File(solrFolder, "solr.xml");
- InputStream is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/solr.xml");
+ InputStream is = EmbeddedSolrHelper.class.getResourceAsStream("/solr.xml");
if (is == null) {
throw new IllegalArgumentException("missing test solr.xml file");
}
@@ -62,14 +64,14 @@ public class EmbeddedSolrHelper {
File solrConfFolder = new File(solrCoreFolder, "conf");
solrConfFolder.mkdir();
File schemaFile = new File(solrConfFolder, "schema.xml");
- is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/schema.xml");
+ is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/schema.xml");
if (is == null) {
throw new IllegalArgumentException("missing test schema.xml file");
}
IOUtils.copy(is, new FileOutputStream(schemaFile));
File solrConfigFile = new File(solrConfFolder, "solrconfig.xml");
- is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/solrconfig.xml");
+ is = EmbeddedSolrHelper.class.getResourceAsStream("/" + configName + "/conf/solrconfig.xml");
if (is == null) {
throw new IllegalArgumentException("missing test solrconfig.xml file");
}
@@ -77,6 +79,10 @@ public class EmbeddedSolrHelper {
// create the embedded server
CoreContainer coreContainer = new CoreContainer(solrFolder.getAbsolutePath(), solrFile);
+ CoreDescriptor coreDescriptor = new CoreDescriptor(coreContainer, coreId,
+ solrCoreFolder.getAbsolutePath());
+ SolrCore core = coreContainer.create(coreDescriptor);
+ coreContainer.register(coreId, core, true);
return new EmbeddedSolrServer(coreContainer, coreId);
}
Modified: incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/training/SolrTrainingSet.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/training/SolrTrainingSet.java?rev=1304811&r1=1304810&r2=1304811&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/training/SolrTrainingSet.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/topic/src/main/java/org/apache/stanbol/enhancer/topic/training/SolrTrainingSet.java Sat Mar 24 14:31:38 2012
@@ -30,6 +30,10 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.ReferencePolicy;
+import org.apache.felix.scr.annotations.ReferenceStrategy;
import org.apache.felix.scr.annotations.Service;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
@@ -38,6 +42,7 @@ import org.apache.solr.client.solrj.resp
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
+import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
import org.apache.stanbol.enhancer.topic.Batch;
import org.apache.stanbol.enhancer.topic.ConfiguredSolrCoreTracker;
import org.apache.stanbol.enhancer.topic.UTCTimeStamper;
@@ -89,6 +94,11 @@ public class SolrTrainingSet extends Con
// TODO: make me configurable using an OSGi property
protected int batchSize = 100;
+ protected String indexName = "default-topic-classifier-trainingset";
+
+ @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, bind = "bindManagedSolrServer", unbind = "unbindManagedSolrServer", strategy = ReferenceStrategy.EVENT, policy = ReferencePolicy.DYNAMIC)
+ protected ManagedSolrServer managedSolrServer;
+
@Activate
protected void activate(ComponentContext context) throws ConfigurationException, InvalidSyntaxException {
@SuppressWarnings("unchecked")
@@ -188,6 +198,7 @@ public class SolrTrainingSet extends Con
query.setRows(1);
query.setFields(exampleIdField);
try {
+ SolrServer solrServer = getActiveSolrServer();
return solrServer.query(query).getResults().size() > 0;
} catch (SolrServerException e) {
String msg = String.format(
Propchange: incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Mar 24 14:31:38 2012
@@ -0,0 +1 @@
+*.solrindex.zip
Added: incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/solr.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/solr.xml?rev=1304811&view=auto
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/solr.xml (added)
+++ incubator/stanbol/trunk/enhancer/engines/topic/src/main/resources/solr.xml Sat Mar 24 14:31:38 2012
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!--
+ SolrYard Configuration for the internally managed Embedded SolrServer:
+
+ By default no cores are defined by this configuration because they are added
+ at runtime via the Java API
+-->
+<solr persistent="false">
+ <cores adminPath="/admin/cores">
+ <!-- Cores are added dynamically at runtime -->
+ </cores>
+</solr>
Modified: incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TopicEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TopicEngineTest.java?rev=1304811&r1=1304810&r2=1304811&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TopicEngineTest.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TopicEngineTest.java Sat Mar 24 14:31:38 2012
@@ -75,12 +75,12 @@ public class TopicEngineTest extends Emb
solrHome = File.createTempFile("topicEngineTest_", "_solr_cores");
solrHome.delete();
solrHome.mkdir();
- classifierSolrServer = makeEmbeddedSolrServer(solrHome, "classifierserver", "classifier",
- "classifier");
+ classifierSolrServer = makeEmbeddedSolrServer(solrHome, "classifierserver", "default-topic-model",
+ "default-topic-model");
classifier = TopicClassificationEngine.fromParameters(getDefaultClassifierConfigParams());
- trainingSetSolrServer = makeEmbeddedSolrServer(solrHome, "trainingsetserver", "trainingset",
- "trainingset");
+ trainingSetSolrServer = makeEmbeddedSolrServer(solrHome, "trainingsetserver",
+ "default-topic-trainingset", "default-topic-trainingset");
trainingSet = new SolrTrainingSet();
trainingSet.configure(getDefaultTrainingSetConfigParams());
}
Modified: incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TrainingSetTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TrainingSetTest.java?rev=1304811&r1=1304810&r2=1304811&view=diff
==============================================================================
--- incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TrainingSetTest.java (original)
+++ incubator/stanbol/trunk/enhancer/engines/topic/src/test/java/org/apache/stanbol/enhancer/engine/topic/TrainingSetTest.java Sat Mar 24 14:31:38 2012
@@ -70,10 +70,11 @@ public class TrainingSetTest extends Emb
solrHome = File.createTempFile("topicTrainingSetTest_", "_solr_cores");
solrHome.delete();
solrHome.mkdir();
- trainingsetSolrServer = makeEmbeddedSolrServer(solrHome, "trainingsetserver", "trainingset",
- "trainingset");
+ trainingsetSolrServer = makeEmbeddedSolrServer(solrHome, "trainingsetserver",
+ "default-topic-trainingset", "default-topic-trainingset");
trainingSet = new SolrTrainingSet();
trainingSet.configure(getDefaultConfigParams());
+
}
@After