Permalink
Browse files

PMML : Initial separation of informer from main PMML module

  • Loading branch information...
1 parent 5d43973 commit 159d47ba53d09e2332c0f14b7cdc0e6c5c5cd5bd @sotty sotty committed Aug 7, 2013
Showing with 20 additions and 16 deletions.
  1. +20 −16 drools-pmml/src/main/java/org/drools/pmml/pmml_4_1/PMML4Compiler.java
@@ -248,7 +248,7 @@ public PMML4Compiler() {
- private static void initVisitor() throws IOException {
+ private static void initVisitor( PMML pmml ) throws IOException {
RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setEventProcessingMode( EventProcessingOption.STREAM );
//conf.setConflictResolver(LifoConflictResolver.getInstance());
@@ -264,13 +264,13 @@ private static void initVisitor() throws IOException {
kBuilder.add( ResourceFactory.newClassPathResource( COMPILER_RULES ), ResourceType.DRL );
compilerRules = true;
}
- if ( informerRules == false ) {
+ if ( informerRules == false && needsInformerExtension( pmml ) ) {
Resource res = ResourceFactory.newClassPathResource( INFORMER_RULES, PMML4Compiler.class );
try {
- if ( res != null && new File( (( ClassPathResource) res).getURL().toURI() ).exists() ) {
+ if ( res != null && (( ClassPathResource) res).getURL().openConnection().getContentType() != null ) {
kBuilder.add( res, ResourceType.DRL );
}
- } catch ( URISyntaxException e ) {
+ } catch ( IOException e ) {
throw new IOException( "Unable to check for informer rules " + e.getMessage() );
}
informerRules = true;
@@ -349,7 +349,7 @@ private static void checkBuildingResources( PMML pmml ) throws IOException {
initRegistry();
}
if ( visitor == null ) {
- initVisitor();
+ initVisitor( pmml );
}
for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) {
@@ -398,6 +398,17 @@ private static void checkBuildingResources( PMML pmml ) throws IOException {
}
}
+ if ( ! informerLoaded && needsInformerExtension( pmml ) ) {
+ for ( String ntempl : INFORMER_TEMPLATES ) {
+ prepareTemplate( ntempl );
+ }
+ informerLoaded = true;
+ }
+
+ }
+
+
+ protected static boolean needsInformerExtension( PMML pmml ) {
for ( Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels() ) {
List inner;
if ( o instanceof AssociationModel ) {
@@ -440,24 +451,17 @@ private static void checkBuildingResources( PMML pmml ) throws IOException {
if ( p instanceof Extension ) {
Extension x = (Extension) p;
for ( Object c : x.getContent() ) {
- if ( ! informerLoaded && c instanceof Element && ((Element) c).getTagName().equals( "Surveyable" ) ) {
- for ( String ntempl : INFORMER_TEMPLATES ) {
- prepareTemplate( ntempl );
- }
- informerLoaded = true;
+ if ( c instanceof Element && ((Element) c).getTagName().equals( "Surveyable" ) ) {
+ return true;
}
}
}
}
- }
-
-
-
+ }
+ return false;
}
-
-
private static void prepareTemplate( String ntempl ) {
try {
String path = TEMPLATE_PATH + ntempl;

0 comments on commit 159d47b

Please sign in to comment.