http://git-wip-us.apache.org/repos/asf/nutch/blob/20d28406/nutch-plugins/index-replace/src/test/java/org/apache/nutch/indexer/replace/TestIndexReplace.java ---------------------------------------------------------------------- diff --git a/nutch-plugins/index-replace/src/test/java/org/apache/nutch/indexer/replace/TestIndexReplace.java b/nutch-plugins/index-replace/src/test/java/org/apache/nutch/indexer/replace/TestIndexReplace.java new file mode 100644 index 0000000..ca90ca3 --- /dev/null +++ b/nutch-plugins/index-replace/src/test/java/org/apache/nutch/indexer/replace/TestIndexReplace.java @@ -0,0 +1,456 @@ +/** + * 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. + */ + +package org.apache.nutch.indexer.replace; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.io.Text; +import org.apache.nutch.crawl.CrawlDatum; +import org.apache.nutch.crawl.Inlinks; +import org.apache.nutch.indexer.NutchDocument; +import org.apache.nutch.indexer.basic.BasicIndexingFilter; +import org.apache.nutch.indexer.metadata.MetadataIndexer; +import org.apache.nutch.parse.Parse; +import org.apache.nutch.parse.ParseUtil; +import org.apache.nutch.protocol.Content; +import org.apache.nutch.protocol.Protocol; +import org.apache.nutch.protocol.ProtocolFactory; +import org.apache.nutch.util.NutchConfiguration; +import org.junit.Assert; +import org.junit.Test; + +/** + * JUnit tests for the <code>index-replace</code> plugin. + * + * In these tests, the sample file has some meta tags added to the Nutch + * document by the <code>index-metadata</code> plugin. The + * <code>index-replace</code> plugin is then used to either change (or not + * change) the fields depending on the various values of + * <code>index.replace.regexp</code> property being provided to Nutch. + * + * + * @author Peter Ciuffetti + * + */ +public class TestIndexReplace { + + private static final String INDEX_REPLACE_PROPERTY = "index.replace.regexp"; + + private String fileSeparator = System.getProperty("file.separator"); + private String sampleDir = System.getProperty("test.data", "."); + private String sampleFile = "testIndexReplace.html"; + + /** + * Run a test file through the Nutch parser and index filters. + * + * @param fileName + * @param conf + * @return the Nutch document with the replace indexer applied + */ + public NutchDocument parseAndFilterFile(String fileName, Configuration conf) { + NutchDocument doc = new NutchDocument(); + + BasicIndexingFilter basicIndexer = new BasicIndexingFilter(); + basicIndexer.setConf(conf); + Assert.assertNotNull(basicIndexer); + + MetadataIndexer metaIndexer = new MetadataIndexer(); + metaIndexer.setConf(conf); + Assert.assertNotNull(basicIndexer); + + ReplaceIndexer replaceIndexer = new ReplaceIndexer(); + replaceIndexer.setConf(conf); + Assert.assertNotNull(replaceIndexer); + + try { + String urlString = "file:" + sampleDir + fileSeparator + fileName; + Text text = new Text(urlString); + CrawlDatum crawlDatum = new CrawlDatum(); + Protocol protocol = new ProtocolFactory(conf).getProtocol(urlString); + Content content = protocol.getProtocolOutput(text, crawlDatum) + .getContent(); + Parse parse = new ParseUtil(conf).parse(content).get(content.getUrl()); + crawlDatum.setFetchTime(100L); + + Inlinks inlinks = new Inlinks(); + doc = basicIndexer.filter(doc, parse, text, crawlDatum, inlinks); + doc = metaIndexer.filter(doc, parse, text, crawlDatum, inlinks); + doc = replaceIndexer.filter(doc, parse, text, crawlDatum, inlinks); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } + + return doc; + } + + /** + * Test property parsing. + * + * The filter does not expose details of the parse. So all we are checking is + * that the parse does not throw a runtime exception and that the value + * provided is the value returned. + */ + @Test + public void testPropertyParse() { + Configuration conf = NutchConfiguration.create(); + String indexReplaceProperty = " metatag.description=/this(.*)plugin/this awesome plugin/2\n" + + " metatag.keywords=/\\,/\\!/\n" + + " hostmatch=.*.com\n" + + " metatag.keywords=/\\,/\\?/\n" + + " metatag.author:dc_author=/\\s+/ David /\n" + + " urlmatch=.*.html\n" + + " metatag.keywords=/\\,/\\./\n" + " metatag.author=/\\s+/ D. /\n"; + + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + + ReplaceIndexer rp = new ReplaceIndexer(); + try { + rp.setConf(conf); + } catch (RuntimeException ohno) { + Assert.fail("Unable to parse a valid index.replace.regexp property! " + + ohno.getMessage()); + } + + Configuration parsedConf = rp.getConf(); + + // Does the getter equal the setter? Too easy! + Assert.assertEquals(indexReplaceProperty, + parsedConf.get(INDEX_REPLACE_PROPERTY)); + } + + /** + * Test metatag value replacement using global replacement settings. + * + * The index.replace.regexp property does not use hostmatch or urlmatch, so + * all patterns are global. + */ + @Test + public void testGlobalReplacement() { + String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; + String expectedKeywords = "Breathtaking! Riveting! Two Thumbs Up!"; + String expectedAuthor = "Peter D. Ciuffetti"; + String indexReplaceProperty = " metatag.description=/this(.*)plugin/this awesome plugin/\n" + + " metatag.keywords=/\\,/\\!/\n" + " metatag.author=/\\s+/ D. /\n"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + Assert + .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); + Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); + } + + /** + * Test that invalid property settings are handled and ignored. + * + * This test provides an invalid property setting that will fail property + * parsing and Pattern.compile. The expected outcome is that the patterns will + * not cause failure and the targeted fields will not be modified by the + * filter. + */ + @Test + public void testInvalidPatterns() { + String expectedDescription = "With this plugin, I control the description! Bwuhuhuhaha!"; + String expectedKeywords = "Breathtaking, Riveting, Two Thumbs Up!"; + String expectedAuthor = "Peter Ciuffetti"; + // Contains: invalid pattern, invalid flags, incomplete property + String indexReplaceProperty = " metatag.description=/this\\s+**plugin/this awesome plugin/\n" + + " metatag.keywords=/\\,/\\!/what\n" + " metatag.author=#notcomplete"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + // Assert that our metatags have not changed. + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + Assert + .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); + Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); + + } + + /** + * Test URL pattern matching + */ + @Test + public void testUrlMatchesPattern() { + String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; + String expectedKeywords = "Breathtaking! Riveting! Two Thumbs Up!"; + String expectedAuthor = "Peter D. Ciuffetti"; + String indexReplaceProperty = " urlmatch=.*.html\n" + + " metatag.description=/this(.*)plugin/this awesome plugin/\n" + + " metatag.keywords=/\\,/\\!/\n" + " metatag.author=/\\s+/ D. /\n"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + // Assert that our metatags have changed. + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + Assert + .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); + Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); + + } + + /** + * Test URL pattern not matching. + * + * Expected result is that the filter does not change the fields. + */ + @Test + public void testUrlNotMatchesPattern() { + String expectedDescription = "With this plugin, I control the description! Bwuhuhuhaha!"; + String expectedKeywords = "Breathtaking, Riveting, Two Thumbs Up!"; + String expectedAuthor = "Peter Ciuffetti"; + String indexReplaceProperty = " urlmatch=.*.xml\n" + + " metatag.description=/this(.*)plugin/this awesome plugin/\n" + + " metatag.keywords=/\\,/\\!/\n" + " metatag.author=/\\s+/ D. /\n"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + // Assert that our metatags have not changed. + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + Assert + .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); + Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); + + } + + /** + * Test a global pattern match for description and URL pattern match for + * keywords and author. + * + * All three should be triggered. It also tests replacement groups. + */ + @Test + public void testGlobalAndUrlMatchesPattern() { + String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; + String expectedKeywords = "Breathtaking! Riveting! Two Thumbs Up!"; + String expectedAuthor = "Peter D. Ciuffetti"; + String indexReplaceProperty = " metatag.description=/this(.*)plugin/this$1awesome$1plugin/\n" + + " urlmatch=.*.html\n" + + " metatag.keywords=/\\,/\\!/\n" + + " metatag.author=/\\s+/ D. /\n"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + // Assert that our metatags have changed. + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + Assert + .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); + Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); + + } + + /** + * Test a global pattern match for description and URL pattern match for + * keywords and author. + * + * Only the global match should be triggered. + */ + @Test + public void testGlobalAndUrlNotMatchesPattern() { + String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; + String expectedKeywords = "Breathtaking, Riveting, Two Thumbs Up!"; + String expectedAuthor = "Peter Ciuffetti"; + String indexReplaceProperty = " metatag.description=/this(.*)plugin/this$1awesome$1plugin/\n" + + " urlmatch=.*.xml\n" + + " metatag.keywords=/\\,/\\!/\n" + + " metatag.author=/\\s+/ D. /\n"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + // Assert that description has changed and the others have not changed. + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + Assert + .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); + Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); + } + + /** + * Test order-specific replacement settings. + * + * This makes multiple replacements on the same field and will produce the + * expected value only if the replacements are run in the order specified. + */ + @Test + public void testReplacementsRunInSpecifedOrder() { + String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; + String indexReplaceProperty = " metatag.description=/this plugin/this amazing plugin/\n" + + " metatag.description=/this amazing plugin/this valuable plugin/\n" + + " metatag.description=/this valuable plugin/this cool plugin/\n" + + " metatag.description=/this cool plugin/this wicked plugin/\n" + + " metatag.description=/this wicked plugin/this awesome plugin/\n"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + // Check that the value produced by the last replacement has worked. + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + } + + /** + * Test a replacement pattern that uses the flags feature. + * + * A 2 is Pattern.CASE_INSENSITIVE. We look for upper case and expect to match + * any case. + */ + @Test + public void testReplacementsWithFlags() { + String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; + String indexReplaceProperty = " metatag.description=/THIS PLUGIN/this awesome plugin/2"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + // Check that the value produced by the case-insensitive replacement has + // worked. + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + } + + /** + * Test a replacement pattern that uses the target field feature. + * Check that the input is not modifid and that the taret field is added. + */ + @Test + public void testReplacementsDifferentTarget() { + String expectedDescription = "With this plugin, I control the description! Bwuhuhuhaha!"; + String expectedTargetDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; + String indexReplaceProperty = " metatag.description:new=/this plugin/this awesome plugin/"; + + Configuration conf = NutchConfiguration.create(); + conf.set( + "plugin.includes", + "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); + conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); + conf.set("metatags.names", "author,description,keywords"); + conf.set("index.parse.md", + "metatag.author,metatag.description,metatag.keywords"); + // Not necessary but helpful when debugging the filter. + conf.set("http.timeout", "99999999999"); + + // Run the document through the parser and index filters. + NutchDocument doc = parseAndFilterFile(sampleFile, conf); + + // Check that the input field has not been modified + Assert.assertEquals(expectedDescription, + doc.getFieldValue("metatag.description")); + // Check that the output field has created + Assert.assertEquals(expectedTargetDescription, + doc.getFieldValue("new")); + } +}
http://git-wip-us.apache.org/repos/asf/nutch/blob/20d28406/nutch-plugins/index-replace/src/test/org/apache/nutch/indexer/replace/TestIndexReplace.java ---------------------------------------------------------------------- diff --git a/nutch-plugins/index-replace/src/test/org/apache/nutch/indexer/replace/TestIndexReplace.java b/nutch-plugins/index-replace/src/test/org/apache/nutch/indexer/replace/TestIndexReplace.java deleted file mode 100644 index ca90ca3..0000000 --- a/nutch-plugins/index-replace/src/test/org/apache/nutch/indexer/replace/TestIndexReplace.java +++ /dev/null @@ -1,456 +0,0 @@ -/** - * 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. - */ - -package org.apache.nutch.indexer.replace; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.io.Text; -import org.apache.nutch.crawl.CrawlDatum; -import org.apache.nutch.crawl.Inlinks; -import org.apache.nutch.indexer.NutchDocument; -import org.apache.nutch.indexer.basic.BasicIndexingFilter; -import org.apache.nutch.indexer.metadata.MetadataIndexer; -import org.apache.nutch.parse.Parse; -import org.apache.nutch.parse.ParseUtil; -import org.apache.nutch.protocol.Content; -import org.apache.nutch.protocol.Protocol; -import org.apache.nutch.protocol.ProtocolFactory; -import org.apache.nutch.util.NutchConfiguration; -import org.junit.Assert; -import org.junit.Test; - -/** - * JUnit tests for the <code>index-replace</code> plugin. - * - * In these tests, the sample file has some meta tags added to the Nutch - * document by the <code>index-metadata</code> plugin. The - * <code>index-replace</code> plugin is then used to either change (or not - * change) the fields depending on the various values of - * <code>index.replace.regexp</code> property being provided to Nutch. - * - * - * @author Peter Ciuffetti - * - */ -public class TestIndexReplace { - - private static final String INDEX_REPLACE_PROPERTY = "index.replace.regexp"; - - private String fileSeparator = System.getProperty("file.separator"); - private String sampleDir = System.getProperty("test.data", "."); - private String sampleFile = "testIndexReplace.html"; - - /** - * Run a test file through the Nutch parser and index filters. - * - * @param fileName - * @param conf - * @return the Nutch document with the replace indexer applied - */ - public NutchDocument parseAndFilterFile(String fileName, Configuration conf) { - NutchDocument doc = new NutchDocument(); - - BasicIndexingFilter basicIndexer = new BasicIndexingFilter(); - basicIndexer.setConf(conf); - Assert.assertNotNull(basicIndexer); - - MetadataIndexer metaIndexer = new MetadataIndexer(); - metaIndexer.setConf(conf); - Assert.assertNotNull(basicIndexer); - - ReplaceIndexer replaceIndexer = new ReplaceIndexer(); - replaceIndexer.setConf(conf); - Assert.assertNotNull(replaceIndexer); - - try { - String urlString = "file:" + sampleDir + fileSeparator + fileName; - Text text = new Text(urlString); - CrawlDatum crawlDatum = new CrawlDatum(); - Protocol protocol = new ProtocolFactory(conf).getProtocol(urlString); - Content content = protocol.getProtocolOutput(text, crawlDatum) - .getContent(); - Parse parse = new ParseUtil(conf).parse(content).get(content.getUrl()); - crawlDatum.setFetchTime(100L); - - Inlinks inlinks = new Inlinks(); - doc = basicIndexer.filter(doc, parse, text, crawlDatum, inlinks); - doc = metaIndexer.filter(doc, parse, text, crawlDatum, inlinks); - doc = replaceIndexer.filter(doc, parse, text, crawlDatum, inlinks); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(e.toString()); - } - - return doc; - } - - /** - * Test property parsing. - * - * The filter does not expose details of the parse. So all we are checking is - * that the parse does not throw a runtime exception and that the value - * provided is the value returned. - */ - @Test - public void testPropertyParse() { - Configuration conf = NutchConfiguration.create(); - String indexReplaceProperty = " metatag.description=/this(.*)plugin/this awesome plugin/2\n" - + " metatag.keywords=/\\,/\\!/\n" - + " hostmatch=.*.com\n" - + " metatag.keywords=/\\,/\\?/\n" - + " metatag.author:dc_author=/\\s+/ David /\n" - + " urlmatch=.*.html\n" - + " metatag.keywords=/\\,/\\./\n" + " metatag.author=/\\s+/ D. /\n"; - - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - - ReplaceIndexer rp = new ReplaceIndexer(); - try { - rp.setConf(conf); - } catch (RuntimeException ohno) { - Assert.fail("Unable to parse a valid index.replace.regexp property! " - + ohno.getMessage()); - } - - Configuration parsedConf = rp.getConf(); - - // Does the getter equal the setter? Too easy! - Assert.assertEquals(indexReplaceProperty, - parsedConf.get(INDEX_REPLACE_PROPERTY)); - } - - /** - * Test metatag value replacement using global replacement settings. - * - * The index.replace.regexp property does not use hostmatch or urlmatch, so - * all patterns are global. - */ - @Test - public void testGlobalReplacement() { - String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; - String expectedKeywords = "Breathtaking! Riveting! Two Thumbs Up!"; - String expectedAuthor = "Peter D. Ciuffetti"; - String indexReplaceProperty = " metatag.description=/this(.*)plugin/this awesome plugin/\n" - + " metatag.keywords=/\\,/\\!/\n" + " metatag.author=/\\s+/ D. /\n"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - Assert - .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); - Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); - } - - /** - * Test that invalid property settings are handled and ignored. - * - * This test provides an invalid property setting that will fail property - * parsing and Pattern.compile. The expected outcome is that the patterns will - * not cause failure and the targeted fields will not be modified by the - * filter. - */ - @Test - public void testInvalidPatterns() { - String expectedDescription = "With this plugin, I control the description! Bwuhuhuhaha!"; - String expectedKeywords = "Breathtaking, Riveting, Two Thumbs Up!"; - String expectedAuthor = "Peter Ciuffetti"; - // Contains: invalid pattern, invalid flags, incomplete property - String indexReplaceProperty = " metatag.description=/this\\s+**plugin/this awesome plugin/\n" - + " metatag.keywords=/\\,/\\!/what\n" + " metatag.author=#notcomplete"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - // Assert that our metatags have not changed. - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - Assert - .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); - Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); - - } - - /** - * Test URL pattern matching - */ - @Test - public void testUrlMatchesPattern() { - String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; - String expectedKeywords = "Breathtaking! Riveting! Two Thumbs Up!"; - String expectedAuthor = "Peter D. Ciuffetti"; - String indexReplaceProperty = " urlmatch=.*.html\n" - + " metatag.description=/this(.*)plugin/this awesome plugin/\n" - + " metatag.keywords=/\\,/\\!/\n" + " metatag.author=/\\s+/ D. /\n"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - // Assert that our metatags have changed. - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - Assert - .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); - Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); - - } - - /** - * Test URL pattern not matching. - * - * Expected result is that the filter does not change the fields. - */ - @Test - public void testUrlNotMatchesPattern() { - String expectedDescription = "With this plugin, I control the description! Bwuhuhuhaha!"; - String expectedKeywords = "Breathtaking, Riveting, Two Thumbs Up!"; - String expectedAuthor = "Peter Ciuffetti"; - String indexReplaceProperty = " urlmatch=.*.xml\n" - + " metatag.description=/this(.*)plugin/this awesome plugin/\n" - + " metatag.keywords=/\\,/\\!/\n" + " metatag.author=/\\s+/ D. /\n"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - // Assert that our metatags have not changed. - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - Assert - .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); - Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); - - } - - /** - * Test a global pattern match for description and URL pattern match for - * keywords and author. - * - * All three should be triggered. It also tests replacement groups. - */ - @Test - public void testGlobalAndUrlMatchesPattern() { - String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; - String expectedKeywords = "Breathtaking! Riveting! Two Thumbs Up!"; - String expectedAuthor = "Peter D. Ciuffetti"; - String indexReplaceProperty = " metatag.description=/this(.*)plugin/this$1awesome$1plugin/\n" - + " urlmatch=.*.html\n" - + " metatag.keywords=/\\,/\\!/\n" - + " metatag.author=/\\s+/ D. /\n"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - // Assert that our metatags have changed. - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - Assert - .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); - Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); - - } - - /** - * Test a global pattern match for description and URL pattern match for - * keywords and author. - * - * Only the global match should be triggered. - */ - @Test - public void testGlobalAndUrlNotMatchesPattern() { - String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; - String expectedKeywords = "Breathtaking, Riveting, Two Thumbs Up!"; - String expectedAuthor = "Peter Ciuffetti"; - String indexReplaceProperty = " metatag.description=/this(.*)plugin/this$1awesome$1plugin/\n" - + " urlmatch=.*.xml\n" - + " metatag.keywords=/\\,/\\!/\n" - + " metatag.author=/\\s+/ D. /\n"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - // Assert that description has changed and the others have not changed. - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - Assert - .assertEquals(expectedKeywords, doc.getFieldValue("metatag.keywords")); - Assert.assertEquals(expectedAuthor, doc.getFieldValue("metatag.author")); - } - - /** - * Test order-specific replacement settings. - * - * This makes multiple replacements on the same field and will produce the - * expected value only if the replacements are run in the order specified. - */ - @Test - public void testReplacementsRunInSpecifedOrder() { - String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; - String indexReplaceProperty = " metatag.description=/this plugin/this amazing plugin/\n" - + " metatag.description=/this amazing plugin/this valuable plugin/\n" - + " metatag.description=/this valuable plugin/this cool plugin/\n" - + " metatag.description=/this cool plugin/this wicked plugin/\n" - + " metatag.description=/this wicked plugin/this awesome plugin/\n"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - // Check that the value produced by the last replacement has worked. - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - } - - /** - * Test a replacement pattern that uses the flags feature. - * - * A 2 is Pattern.CASE_INSENSITIVE. We look for upper case and expect to match - * any case. - */ - @Test - public void testReplacementsWithFlags() { - String expectedDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; - String indexReplaceProperty = " metatag.description=/THIS PLUGIN/this awesome plugin/2"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - // Check that the value produced by the case-insensitive replacement has - // worked. - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - } - - /** - * Test a replacement pattern that uses the target field feature. - * Check that the input is not modifid and that the taret field is added. - */ - @Test - public void testReplacementsDifferentTarget() { - String expectedDescription = "With this plugin, I control the description! Bwuhuhuhaha!"; - String expectedTargetDescription = "With this awesome plugin, I control the description! Bwuhuhuhaha!"; - String indexReplaceProperty = " metatag.description:new=/this plugin/this awesome plugin/"; - - Configuration conf = NutchConfiguration.create(); - conf.set( - "plugin.includes", - "protocol-file|urlfilter-regex|parse-(html|metatags)|index-(basic|anchor|metadata|static|replace)|urlnormalizer-(pass|regex|basic)"); - conf.set(INDEX_REPLACE_PROPERTY, indexReplaceProperty); - conf.set("metatags.names", "author,description,keywords"); - conf.set("index.parse.md", - "metatag.author,metatag.description,metatag.keywords"); - // Not necessary but helpful when debugging the filter. - conf.set("http.timeout", "99999999999"); - - // Run the document through the parser and index filters. - NutchDocument doc = parseAndFilterFile(sampleFile, conf); - - // Check that the input field has not been modified - Assert.assertEquals(expectedDescription, - doc.getFieldValue("metatag.description")); - // Check that the output field has created - Assert.assertEquals(expectedTargetDescription, - doc.getFieldValue("new")); - } -} http://git-wip-us.apache.org/repos/asf/nutch/blob/20d28406/nutch-plugins/index-static/src/test/java/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java ---------------------------------------------------------------------- diff --git a/nutch-plugins/index-static/src/test/java/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java b/nutch-plugins/index-static/src/test/java/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java new file mode 100644 index 0000000..42cd46d --- /dev/null +++ b/nutch-plugins/index-static/src/test/java/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java @@ -0,0 +1,194 @@ +/* + * 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. + */ +package org.apache.nutch.indexer.staticfield; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.io.Text; +import org.apache.nutch.crawl.CrawlDatum; +import org.apache.nutch.crawl.Inlinks; +import org.apache.nutch.indexer.NutchDocument; +import org.apache.nutch.parse.ParseImpl; +import org.apache.nutch.util.NutchConfiguration; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * JUnit test case which tests 1. that static data fields are added to a + * document 2. that empty {@code index.static} does not add anything to the + * document 3. that valid field:value pairs are added to the document 4. that + * fields and values added to the document are trimmed + * + * @author tejasp + */ + +public class TestStaticFieldIndexerTest { + + Configuration conf; + + Inlinks inlinks; + ParseImpl parse; + CrawlDatum crawlDatum; + Text url; + StaticFieldIndexer filter; + + @Before + public void setUp() throws Exception { + conf = NutchConfiguration.create(); + parse = new ParseImpl(); + url = new Text("http://nutch.apache.org/index.html"); + crawlDatum = new CrawlDatum(); + inlinks = new Inlinks(); + filter = new StaticFieldIndexer(); + } + + /** + * Test that empty {@code index.static} does not add anything to the document + * + * @throws Exception + */ + @Test + public void testEmptyIndexStatic() throws Exception { + + Assert.assertNotNull(filter); + filter.setConf(conf); + + NutchDocument doc = new NutchDocument(); + + try { + filter.filter(doc, parse, url, crawlDatum, inlinks); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + Assert.assertNotNull(doc); + Assert.assertTrue("tests if no field is set for empty index.static", doc + .getFieldNames().isEmpty()); + } + + /** + * Test that valid field:value pairs are added to the document + * + * @throws Exception + */ + @Test + public void testNormalScenario() throws Exception { + + conf.set("index.static", + "field1:val1, field2 : val2 val3 , field3, field4 :val4 , "); + Assert.assertNotNull(filter); + filter.setConf(conf); + + NutchDocument doc = new NutchDocument(); + + try { + filter.filter(doc, parse, url, crawlDatum, inlinks); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + Assert.assertNotNull(doc); + Assert.assertFalse("test if doc is not empty", doc.getFieldNames() + .isEmpty()); + Assert.assertEquals("test if doc has 3 fields", 3, doc.getFieldNames() + .size()); + Assert.assertTrue("test if doc has field1", doc.getField("field1") + .getValues().contains("val1")); + Assert.assertTrue("test if doc has field2", doc.getField("field2") + .getValues().contains("val2")); + Assert.assertTrue("test if doc has field4", doc.getField("field4") + .getValues().contains("val4")); + } + + /** + * Test for NUTCH-2052 custom delimiters in index.static. + * + * @throws Exception + */ + @Test + public void testCustomDelimiters() throws Exception { + + conf.set("index.static.fieldsep", ">"); + conf.set("index.static.keysep", "="); + conf.set("index.static.valuesep", "|"); + conf.set("index.static", + "field1=val1>field2 = val2|val3 >field3>field4 =val4 > "); + Assert.assertNotNull(filter); + filter.setConf(conf); + + NutchDocument doc = new NutchDocument(); + + try { + filter.filter(doc, parse, url, crawlDatum, inlinks); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + Assert.assertNotNull(doc); + Assert.assertFalse("test if doc is not empty", doc.getFieldNames() + .isEmpty()); + Assert.assertEquals("test if doc has 3 fields", 3, doc.getFieldNames() + .size()); + Assert.assertTrue("test if doc has field1", doc.getField("field1") + .getValues().contains("val1")); + Assert.assertTrue("test if doc has field2", doc.getField("field2") + .getValues().contains("val2")); + Assert.assertTrue("test if doc has field4", doc.getField("field4") + .getValues().contains("val4")); + } + + /** + * Test for NUTCH-2052 custom delimiters in index.static. + * + * @throws Exception + */ + @Test + public void testCustomMulticharacterDelimiters() throws Exception { + + conf.set("index.static.fieldsep", "\n\n"); + conf.set("index.static.keysep", "\t\t"); + conf.set("index.static.valuesep", "***"); + conf.set("index.static", "field1\t\tval1\n\n" + "field2\t\tval2***val3\n\n" + + "field3\n\n" + "field4\t\tval4\n\n\n\n"); + Assert.assertNotNull(filter); + filter.setConf(conf); + + NutchDocument doc = new NutchDocument(); + + try { + filter.filter(doc, parse, url, crawlDatum, inlinks); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } + + Assert.assertNotNull(doc); + Assert.assertFalse("test if doc is not empty", doc.getFieldNames() + .isEmpty()); + Assert.assertEquals("test if doc has 3 fields", 3, doc.getFieldNames() + .size()); + Assert.assertTrue("test if doc has field1", doc.getField("field1") + .getValues().contains("val1")); + Assert.assertTrue("test if doc has field2", doc.getField("field2") + .getValues().contains("val2")); + Assert.assertTrue("test if doc has field4", doc.getField("field4") + .getValues().contains("val4")); + } +} http://git-wip-us.apache.org/repos/asf/nutch/blob/20d28406/nutch-plugins/index-static/src/test/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java ---------------------------------------------------------------------- diff --git a/nutch-plugins/index-static/src/test/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java b/nutch-plugins/index-static/src/test/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java deleted file mode 100644 index 42cd46d..0000000 --- a/nutch-plugins/index-static/src/test/org/apache/nutch/indexer/staticfield/TestStaticFieldIndexerTest.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * 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. - */ -package org.apache.nutch.indexer.staticfield; - -import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.io.Text; -import org.apache.nutch.crawl.CrawlDatum; -import org.apache.nutch.crawl.Inlinks; -import org.apache.nutch.indexer.NutchDocument; -import org.apache.nutch.parse.ParseImpl; -import org.apache.nutch.util.NutchConfiguration; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * JUnit test case which tests 1. that static data fields are added to a - * document 2. that empty {@code index.static} does not add anything to the - * document 3. that valid field:value pairs are added to the document 4. that - * fields and values added to the document are trimmed - * - * @author tejasp - */ - -public class TestStaticFieldIndexerTest { - - Configuration conf; - - Inlinks inlinks; - ParseImpl parse; - CrawlDatum crawlDatum; - Text url; - StaticFieldIndexer filter; - - @Before - public void setUp() throws Exception { - conf = NutchConfiguration.create(); - parse = new ParseImpl(); - url = new Text("http://nutch.apache.org/index.html"); - crawlDatum = new CrawlDatum(); - inlinks = new Inlinks(); - filter = new StaticFieldIndexer(); - } - - /** - * Test that empty {@code index.static} does not add anything to the document - * - * @throws Exception - */ - @Test - public void testEmptyIndexStatic() throws Exception { - - Assert.assertNotNull(filter); - filter.setConf(conf); - - NutchDocument doc = new NutchDocument(); - - try { - filter.filter(doc, parse, url, crawlDatum, inlinks); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - - Assert.assertNotNull(doc); - Assert.assertTrue("tests if no field is set for empty index.static", doc - .getFieldNames().isEmpty()); - } - - /** - * Test that valid field:value pairs are added to the document - * - * @throws Exception - */ - @Test - public void testNormalScenario() throws Exception { - - conf.set("index.static", - "field1:val1, field2 : val2 val3 , field3, field4 :val4 , "); - Assert.assertNotNull(filter); - filter.setConf(conf); - - NutchDocument doc = new NutchDocument(); - - try { - filter.filter(doc, parse, url, crawlDatum, inlinks); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - - Assert.assertNotNull(doc); - Assert.assertFalse("test if doc is not empty", doc.getFieldNames() - .isEmpty()); - Assert.assertEquals("test if doc has 3 fields", 3, doc.getFieldNames() - .size()); - Assert.assertTrue("test if doc has field1", doc.getField("field1") - .getValues().contains("val1")); - Assert.assertTrue("test if doc has field2", doc.getField("field2") - .getValues().contains("val2")); - Assert.assertTrue("test if doc has field4", doc.getField("field4") - .getValues().contains("val4")); - } - - /** - * Test for NUTCH-2052 custom delimiters in index.static. - * - * @throws Exception - */ - @Test - public void testCustomDelimiters() throws Exception { - - conf.set("index.static.fieldsep", ">"); - conf.set("index.static.keysep", "="); - conf.set("index.static.valuesep", "|"); - conf.set("index.static", - "field1=val1>field2 = val2|val3 >field3>field4 =val4 > "); - Assert.assertNotNull(filter); - filter.setConf(conf); - - NutchDocument doc = new NutchDocument(); - - try { - filter.filter(doc, parse, url, crawlDatum, inlinks); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - - Assert.assertNotNull(doc); - Assert.assertFalse("test if doc is not empty", doc.getFieldNames() - .isEmpty()); - Assert.assertEquals("test if doc has 3 fields", 3, doc.getFieldNames() - .size()); - Assert.assertTrue("test if doc has field1", doc.getField("field1") - .getValues().contains("val1")); - Assert.assertTrue("test if doc has field2", doc.getField("field2") - .getValues().contains("val2")); - Assert.assertTrue("test if doc has field4", doc.getField("field4") - .getValues().contains("val4")); - } - - /** - * Test for NUTCH-2052 custom delimiters in index.static. - * - * @throws Exception - */ - @Test - public void testCustomMulticharacterDelimiters() throws Exception { - - conf.set("index.static.fieldsep", "\n\n"); - conf.set("index.static.keysep", "\t\t"); - conf.set("index.static.valuesep", "***"); - conf.set("index.static", "field1\t\tval1\n\n" + "field2\t\tval2***val3\n\n" - + "field3\n\n" + "field4\t\tval4\n\n\n\n"); - Assert.assertNotNull(filter); - filter.setConf(conf); - - NutchDocument doc = new NutchDocument(); - - try { - filter.filter(doc, parse, url, crawlDatum, inlinks); - } catch (Exception e) { - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - - Assert.assertNotNull(doc); - Assert.assertFalse("test if doc is not empty", doc.getFieldNames() - .isEmpty()); - Assert.assertEquals("test if doc has 3 fields", 3, doc.getFieldNames() - .size()); - Assert.assertTrue("test if doc has field1", doc.getField("field1") - .getValues().contains("val1")); - Assert.assertTrue("test if doc has field2", doc.getField("field2") - .getValues().contains("val2")); - Assert.assertTrue("test if doc has field4", doc.getField("field4") - .getValues().contains("val4")); - } -} http://git-wip-us.apache.org/repos/asf/nutch/blob/20d28406/nutch-plugins/language-identifier/src/test/java/org/apache/nutch/analysis/lang/TestHTMLLanguageParser.java ---------------------------------------------------------------------- diff --git a/nutch-plugins/language-identifier/src/test/java/org/apache/nutch/analysis/lang/TestHTMLLanguageParser.java b/nutch-plugins/language-identifier/src/test/java/org/apache/nutch/analysis/lang/TestHTMLLanguageParser.java new file mode 100644 index 0000000..8245151 --- /dev/null +++ b/nutch-plugins/language-identifier/src/test/java/org/apache/nutch/analysis/lang/TestHTMLLanguageParser.java @@ -0,0 +1,149 @@ +/** + * 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. + */ +package org.apache.nutch.analysis.lang; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +// Nutch imports +import org.apache.nutch.metadata.Metadata; +import org.apache.nutch.parse.Parse; +import org.apache.nutch.parse.ParseUtil; +import org.apache.nutch.protocol.Content; +import org.apache.nutch.util.NutchConfiguration; +import org.apache.tika.language.LanguageIdentifier; +import org.junit.Assert; +import org.junit.Test; + +public class TestHTMLLanguageParser { + + private static String URL = "http://foo.bar/"; + + private static String BASE = "http://foo.bar/"; + + String docs[] = { + "<html lang=\"fi\"><head>document 1 title</head><body>jotain suomeksi</body></html>", + "<html><head><meta http-equiv=\"content-language\" content=\"en\"><title>document 2 title</head><body>this is english</body></html>", + "<html><head><meta name=\"dc.language\" content=\"en\"><title>document 3 title</head><body>this is english</body></html>" }; + + // Tika does not return "fi" but null + String metalanguages[] = { "fi", "en", "en" }; + + /** + * Test parsing of language identifiers from html + **/ + @Test + public void testMetaHTMLParsing() { + + try { + ParseUtil parser = new ParseUtil(NutchConfiguration.create()); + /* loop through the test documents and validate result */ + for (int t = 0; t < docs.length; t++) { + Content content = getContent(docs[t]); + Parse parse = parser.parse(content).get(content.getUrl()); + Assert.assertEquals(metalanguages[t], (String) parse.getData() + .getParseMeta().get(Metadata.LANGUAGE)); + } + } catch (Exception e) { + e.printStackTrace(System.out); + Assert.fail(e.toString()); + } + + } + + /** Test of <code>LanguageParser.parseLanguage(String)</code> method. */ + @Test + public void testParseLanguage() { + String tests[][] = { { "(SCHEME=ISO.639-1) sv", "sv" }, + { "(SCHEME=RFC1766) sv-FI", "sv" }, { "(SCHEME=Z39.53) SWE", "sv" }, + { "EN_US, SV, EN, EN_UK", "en" }, { "English Swedish", "en" }, + { "English, swedish", "en" }, { "English,Swedish", "en" }, + { "Other (Svenska)", "sv" }, { "SE", "se" }, { "SV", "sv" }, + { "SV charset=iso-8859-1", "sv" }, { "SV-FI", "sv" }, + { "SV; charset=iso-8859-1", "sv" }, { "SVE", "sv" }, { "SW", "sw" }, + { "SWE", "sv" }, { "SWEDISH", "sv" }, { "Sv", "sv" }, { "Sve", "sv" }, + { "Svenska", "sv" }, { "Swedish", "sv" }, { "Swedish, svenska", "sv" }, + { "en, sv", "en" }, { "sv", "sv" }, + { "sv, be, dk, de, fr, no, pt, ch, fi, en", "sv" }, { "sv,en", "sv" }, + { "sv-FI", "sv" }, { "sv-SE", "sv" }, { "sv-en", "sv" }, + { "sv-fi", "sv" }, { "sv-se", "sv" }, + { "sv; Content-Language: sv", "sv" }, { "sv_SE", "sv" }, + { "sve", "sv" }, { "svenska, swedish, engelska, english", "sv" }, + { "sw", "sw" }, { "swe", "sv" }, { "swe.SPR.", "sv" }, + { "sweden", "sv" }, { "swedish", "sv" }, { "swedish,", "sv" }, + { "text/html; charset=sv-SE", "sv" }, { "text/html; sv", "sv" }, + { "torp, stuga, uthyres, bed & breakfast", null } }; + + for (int i = 0; i < 44; i++) { + Assert.assertEquals(tests[i][1], + HTMLLanguageParser.LanguageParser.parseLanguage(tests[i][0])); + } + } + + private Content getContent(String text) { + Metadata meta = new Metadata(); + meta.add("Content-Type", "text/html"); + return new Content(URL, BASE, text.getBytes(), "text/html", meta, + NutchConfiguration.create()); + } + + @Test + public void testLanguageIndentifier() { + try { + long total = 0; + LanguageIdentifier identifier; + BufferedReader in = new BufferedReader(new InputStreamReader(this + .getClass().getResourceAsStream("test-referencial.txt"))); + String line = null; + while ((line = in.readLine()) != null) { + String[] tokens = line.split(";"); + if (!tokens[0].equals("")) { + StringBuilder content = new StringBuilder(); + // Test each line of the file... + BufferedReader testFile = new BufferedReader(new InputStreamReader( + this.getClass().getResourceAsStream(tokens[0]), "UTF-8")); + String testLine = null, lang = null; + while ((testLine = testFile.readLine()) != null) { + content.append(testLine + "\n"); + testLine = testLine.trim(); + if (testLine.length() > 256) { + identifier = new LanguageIdentifier(testLine); + lang = identifier.getLanguage(); + Assert.assertEquals(tokens[1], lang); + } + } + testFile.close(); + + // Test the whole file + long start = System.currentTimeMillis(); + System.out.println(content.toString()); + identifier = new LanguageIdentifier(content.toString()); + lang = identifier.getLanguage(); + System.out.println(lang); + total += System.currentTimeMillis() - start; + Assert.assertEquals(tokens[1], lang); + } + } + in.close(); + System.out.println("Total Time=" + total); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.toString()); + } + } + +} http://git-wip-us.apache.org/repos/asf/nutch/blob/20d28406/nutch-plugins/language-identifier/src/test/java/org/apache/nutch/analysis/lang/da.test ---------------------------------------------------------------------- diff --git a/nutch-plugins/language-identifier/src/test/java/org/apache/nutch/analysis/lang/da.test b/nutch-plugins/language-identifier/src/test/java/org/apache/nutch/analysis/lang/da.test new file mode 100644 index 0000000..1238cd5 --- /dev/null +++ b/nutch-plugins/language-identifier/src/test/java/org/apache/nutch/analysis/lang/da.test @@ -0,0 +1,108 @@ +Genoptagelse af sessionen +Jeg erklærer Europa-Parlamentets session, der blev afbrudt fredag den 17. december, for genoptaget. Endnu en gang vil jeg ønske Dem godt nytÃ¥r, og jeg hÃ¥ber, De har haft en god ferie. +Som De kan se, indfandt det store "Ã¥r 2000-problem" sig ikke. Til gengæld har borgerne i en del af medlemslandene været ramt af meget forfærdelige naturkatastrofer. De har udtrykt ønske om en debat om dette emne i løbet af mødeperioden. I mellemtiden ønsker jeg - som ogsÃ¥ en del kolleger har anmodet om - at vi iagttager et minuts stilhed til minde om ofrene for bl.a. stormene i de medlemslande, der blev ramt. Jeg opfordrer Dem til stÃ¥ende at iagttage et minuts stilhed. +(Parlamentet iagttog stÃ¥ende et minuts stilhed + +Fru formand, en bemærkning til forretningsordenen. Gennem pressen og tv vil De være bekendt med en række bombeeksplosioner og drab i Sri Lanka. En af de personer, der blev myrdet for ganske nylig i Sri Lanka, var hr. Kumar Ponnambalam, der besøgte Europa-Parlamentet for fÃ¥ mÃ¥neder siden. Ville det være passende, hvis De, fru formand, sendte en skrivelse til Sri Lankas præsident for at udtrykke vores dybe beklagelse i forbindelse med Kumar Ponnambalams død og de andre voldsomme dødsfald i Sri Lanka og for indtrængende at anmode præsidenten om at gøre alt for at opnÃ¥ en fredelig løsning pÃ¥ en meget vanskelig situation? + +Ja, hr. Evans, jeg mener, at et initiativ, som det, De foreslÃ¥r, ville være meget hensigtsmæssigt. Hvis Europa-Parlamentet er enigt, vil jeg gøre, som hr. Evans har foreslÃ¥et. + +Fru formand, en bemærkning til forretningsordenen. Jeg vil gerne have Deres rÃ¥d om artikel 143 vedrørende afvisning. Mit spørgsmÃ¥l omhandler et emne, der vil blive behandlet pÃ¥ torsdag, og jeg vil gerne tage emnet op igen ved den lejlighed. +Betænkningen af Cunha om flerÃ¥rige udviklingsprogrammer skal forhandles af Parlamentet pÃ¥ torsdag og indeholder et forslag i punkt 6 om, at der skal indføres kvotesanktioner for lande, der ikke overholder deres Ã¥rlige mÃ¥lsætninger for flÃ¥dereduktion. Dette skal i henhold til punkt 6 indføres til trods for princippet om relativ stabilitet. Jeg mener, at princippet om relativ stabilitet er et grundlæggende retsprincip for den fælles fiskeripolitik, og at der vil være juridisk belæg for at afvise et forslag om at undergrave dette princip. Jeg vil gerne vide, om man kan gøre indsigelse mod noget, der bare er en betænkning og ikke et forslag til retsakt, og om det er noget, jeg kan gøre pÃ¥ torsdag? + +Det er netop dér, De - hvis De ønsker det - kan rejse dette spørgsmÃ¥l, det vil sige pÃ¥ torsdag ved forhandlingens begyndelse. + +Fru formand, samtidig med Europa-Parlamentets første mødeperiode i Ã¥r har man i Texas i USA fastsat datoen for henrettelsen af en dødsdømt, nemlig en ung mand pÃ¥ 34 Ã¥r ved navn Hicks, og det er desværre pÃ¥ næste torsdag. +PÃ¥ anmodning af et fransk parlamentsmedlem, hr. Zimeray, er der allerede indgivet et andragende, som mange har skrevet under pÃ¥, heriblandt undertegnede, men i trÃ¥d med den holdning, som Europa-Parlamentet og hele Det Europæiske Fællesskab konstant giver udtryk for, anmoder jeg Dem om at gøre den indflydelse, De har i kraft af Deres embede og den institution, De repræsenterer, gældende over for præsidenten og Texas' guvernør Bush, som har beføjelse til at ophæve dødsdommen og benÃ¥de den dømte. +Alt dette er i trÃ¥d med de principper, vi altid har været tilhængere af. + +Tak, hr. Segni, det gør jeg med glæde. Det er sÃ¥ledes helt i trÃ¥d med den holdning, Europa-Parlamentet altid har indtaget. + +Fru formand, jeg vil gerne gøre Dem opmærksom pÃ¥ en sag, som Parlamentet har beskæftiget sig med gentagne gange. Det drejer sig om Alexander Nikitin. Vi glæder os alle sammen over, at domstolen har frifundet ham og understreget, at adgangen til miljøinformationer ogsÃ¥ er konstitutionel ret i Rusland. Men nu er det sÃ¥dan, at han skal anklages igen, fordi statsadvokaten har anket dommen. Vi ved og har fastslÃ¥et i virkelig mange beslutninger - netop pÃ¥ det sidste møde sidste Ã¥r - at dette ikke bare er en juridisk sag, og at det er forkert at beskylde Alexander Nikitin for at have begÃ¥et kriminalitet og forræderi, fordi vi som berørte nyder godt af hans resultater. Disse resultater er grundlaget for de europæiske programmer til beskyttelse af Barentsee, og derfor beder jeg Dem gennemgÃ¥ et brevudkast, som beskriver de vigtigste fakta, og tydeliggøre denne holdning i Rusland i overensstemmelse med Parlamentets beslutninger. + +Ja, fru Schroedter, jeg skal med glæde undersøge dette spørgsmÃ¥l, nÃ¥r jeg har modtaget Deres brev. + +Fru formand, jeg vil gerne først give Dem en kompliment for den kendsgerning, at De har holdt Deres ord, og at antallet af tv-kanaler pÃ¥ vores kontorer faktisk er udvidet enormt nu i denne første mødeperiode i det nye Ã¥r. Men, fru formand, det, som jeg havde anmodet om, er ikke sket. Der er nu ganske vist to finske kanaler og en portugisisk kanal, men der er stadig ingen nederlandsk kanal, og jeg havde anmodet Dem om en nederlandsk kanal, fordi ogsÃ¥ nederlændere gerne vil følge med i nyhederne hver mÃ¥ned, nÃ¥r vi forvises til dette sted. Jeg vil sÃ¥ledes endnu en gang anmode Dem om alligevel at sørge for, at vi ogsÃ¥ fÃ¥r en nederlandsk kanal. + +Fru Plooij-van Gorsel, jeg kan oplyse Dem om, at dette spørgsmÃ¥l er opført pÃ¥ dagsordenen for kvæstorernes møde pÃ¥ onsdag. Det vil, hÃ¥ber jeg, blive behandlet i en positiv Ã¥nd. + +Fru formand, kan De fortælle mig, hvorfor Parlamentet ikke overholder de lovgivningsbestemmelser om sundhed og sikkerhed, som det selv har fastsat? Hvorfor er der ikke foretaget en undersøgelse af luftkvaliteten i denne bygning, siden vi blev valgt? Hvorfor har Sundheds- og Sikkerhedsudvalget ikke haft et møde siden 1998? Hvorfor har der ikke været brandøvelser, hverken i parlamentsbygningerne i Bruxelles eller Strasbourg? Hvorfor er der ingen brandinstrukser? Hvorfor etableres der ikke omrÃ¥der med rygeforbud? Det er fuldstændig skandaløst, at vi fastsætter lovgivningsbestemmelser og sÃ¥ ikke overholder dem selv. + +Fru Lynne, De har fuldstændig ret, og jeg vil kontrollere, om alle disse ting virkelig ikke er blevet gjort. Jeg vil ligeledes fremlægge problemet for kvæstorerne, og jeg er sikker pÃ¥, at kvæstorerne vil bestræbe sig pÃ¥ at sørge for, at vi overholder den lovgivning, vi vedtager. + +Fru formand, fru DÃez González og jeg havde stillet nogle spørgsmÃ¥l om visse holdninger gengivet i en spansk avis, som næstformanden, fru de Palacio, har givet udtryk for. De kompetente tjenestegrene har ikke opført dem pÃ¥ dagsordenen, fordi de mener, at de blev besvaret ved et tidligere møde. +Jeg anmoder om, at denne beslutning tages op til fornyet overvejelse, for det er ikke tilfældet. De spørgsmÃ¥l, der tidligere er blevet besvaret, drejede sig om fru de Palacios medvirken i en bestemt sag og ikke om de erklæringer, som kunne læses i avisen ABC den 18. november sidste Ã¥r. + +Kære kolleger, vi vil undersøge alt dette. Jeg mÃ¥ indrømme, at det hele forekommer mig lidt forvirrende i øjeblikket. Derfor vil vi undersøge det meget omhyggeligt, sÃ¥ledes at alt er, som det skal være. + +Fru formand, jeg vil gerne vide, om der kommer en klar melding fra Parlamentet i denne uge om vores utilfredshed i forbindelse med dagens beslutning om ikke at forlænge embargoen mod vÃ¥beneksport til Indonesien i betragtning af, at et stort flertal i Parlamentet tidligere har undertegnet vÃ¥benembargoen i Indonesien. Dagens beslutning om ikke at forlænge embargoen er meget farlig pÃ¥ grund af situationen der. Parlamentet bør derfor tilkendegive sin holdning, da det er flertallets ønske. Det er uansvarligt af EU-medlemsstater at nægte at forlænge embargoen. Som nævnt tidligere er der tale om en meget ustabil situation. Der er endog fare for et militærkup i fremtiden. Vi ved ikke, hvad der sker. SÃ¥ hvorfor skal vÃ¥benproducenter i EU profitere pÃ¥ bekostning af uskyldige mennesker? + +Under alle omstændigheder er punktet ikke pÃ¥ nuværende tidspunkt opført under forhandlingen om aktuelle og uopsættelige spørgsmÃ¥l pÃ¥ torsdag. + +Arbejdsplan +Næste punkt pÃ¥ dagsordenen er fastsættelse af arbejdsplanen. +Det endelige forslag til dagsorden, som det blev opstillet af Formandskonferencen pÃ¥ mødet torsdag den 13. januar i overensstemmelse med forretningsordenens artikel 95, er omdelt. +Det foreligger ingen forslag til ændring for mandag og tirsdag. +Onsdag: +PSE-gruppen anmoder om at fÃ¥ en redegørelse fra Kommissionen om dens strategiske mÃ¥l for de kommende fem Ã¥r samt om den administrative reform opført pÃ¥ dagsordenen. +Hvis hr. Barón Crespo, der har fremsat anmodningen, ønsker det, opfordrer jeg ham til at begrunde sit forslag. Dernæst gør vi, som vi plejer, det vil sige, at vi hører et indlæg for og et indlæg imod forslaget. + +Fru formand, forelæggelsen af Prodi-Kommissionens politiske program for hele valgperioden var til at begynde med et forslag fra De Europæiske Socialdemokraters Gruppe, som opnÃ¥ede enstemmighed pÃ¥ Formandskonferencen i september og ogsÃ¥ hr. Prodis udtrykkelige accept, og han gentog sit løfte i sin indsættelsestale. +Dette løfte er vigtigt, fordi Kommissionen er et organ, der har initiativmonopol i henhold til traktaterne og derfor grundlæggende udformer Parlamentets politiske arbejde og lovgivningsarbejde i de kommende fem Ã¥r. Jeg vil ogsÃ¥ minde om, fru formand, at Parlamentet to gange i foregÃ¥ende valgperiode ved afstemning gav udtryk for sin tillid til formand Prodi. I denne valgperiode igen i juli og senere, med den nye Kommission pÃ¥ plads, gav det igen i september hele Kommissionen et tillidsvotum. Der har derfor været tid nok til, at Kommissionen kunne forberede sit program, og til at vi kunne fÃ¥ kendskab til det og forklare det til borgerne. I den forbindelse vil jeg minde om beslutningen fra 15. september, hvori der blev henstillet til, at forslaget blev forelagt hurtigst muligt. +Det, der skete i sidste uge - og som opstod uden for Formandskonferencen, hvor den udelukkende blev brugt til at bekræfte og godkende beslutninger, som var truffet uden for den - skaber et dilemma: Enten er Kommissionen ikke i stand til at fremlægge det program. (I sÃ¥ fald ville det være passende, at den informerede om det. Ifølge kommissionsformandens udsagn er de i stand til at gøre det. Eftersom Kommissionen er repræsenteret af næstformanden, fru de Palacio, mener jeg, at det før afstemningen ville være pÃ¥ sin plads at være pÃ¥ det rene med Kommissionens situation, hvad angÃ¥r dets vilje til at forelægge programmet, ligesom det var blevet aftalt.) Eller ogsÃ¥ er Parlamentet ikke i stand til at behandle dette program, som der vist er nogle, der pÃ¥stÃ¥r. Efter min mening ville denne anden hypotese være det samme som at give afkald pÃ¥ vores ansvar som parlament og desuden at indføre en original teori, en ukendt metode, der bestÃ¥r i skriftligt at give de politiske g rupper kendskab til Kommissionens program en uge før - og ikke dagen før, som det var aftalen - i betragtning af, at lovgivningsprogrammet skal diskuteres i februar, sÃ¥ledes at vi kunne springe forhandlingen over, fordi pressen og Internettet dagen efter havde givet alle borgerne kendskab til det, og Parlamentet ville ikke længere behøve at bekymre sig om sagen. +Da min gruppe mener, at et parlament er til for at lytte, diskutere og overveje, mener vi, at der ikke er noget som helst, der kan retfærdiggøre denne udsættelse, og vi mener, at hvis Kommissionen er i stand til at gøre det, er der tid nok til, at vi kan genetablere den oprindelige aftale mellem Parlamentet og Kommissionen og handle ansvarligt over for vores medborgere. Derfor gÃ¥r det forslag, som De Europæiske Socialdemokraters Gruppe stiller, og som De har nævnt, ud pÃ¥, at vi holder fast ved forelæggelsen af Prodi-Kommissionens program for valgperioden pÃ¥ onsdag, og at dette program ogsÃ¥ omfatter forslaget til administrativ reform, for hvis det ikke bliver sÃ¥dan, kan vi komme i en paradoksal situation: Med en undskyldning om at der ikke er en tekst, nægtes formanden for Kommissionen pÃ¥ den ene side retten til at tale i Parlamentet, og pÃ¥ den anden side forhindres det, at der finder en forhandling sted om reformen, uden at Parlamentet pÃ¥ forhÃ¥nd kender de tekster, som den er baseret pÃ¥. Derfor, fru formand, anmoder jeg Dem om at bede Kommissionen om at udtale sig nu, og at vi derefter gÃ¥r over til afstemning. +(Bifald fra PSE-gruppen) + +Fru formand, kære kolleger, jeg er godt nok noget forbavset over vores kollega Barón Crespos opførsel. Han forlanger nu, at dette punkt sættes pÃ¥ dagsordenen for onsdag. +Hr. Barón Crespo, De kunne ikke deltage den sidste torsdag pÃ¥ Formandskonferencen. Det kritiserer jeg ikke, for det sker af og til, at man lader sig repræsentere. Hr. Hänsch repræsenterede Dem dér. Vi havde en udførlig debat pÃ¥ Formandskonferencen. Kun Deres gruppe repræsenterede det, som De siger nu. Vi stemte derefter om det. Hver ordfører har jo lige sÃ¥ mange stemmer, som der er medlemmer i gruppen. Der var en afstemning om dette punkt. SÃ¥ vidt jeg husker, faldt denne afstemning sÃ¥ledes ud: 422 mod 180 stemmer og nogle fÃ¥, der undlod at stemme. Det vil sige, at alle grupper med undtagelse af løsgængerne - men de udgør jo ikke nogen gruppe - var enige, kun Deres gruppe mente, at man skulle bære sig sÃ¥dan ad, som De har foreslÃ¥et her. Alle andre mente noget andet. Det var beslutningen. +Nu vil jeg gerne sige noget til selve sagen. Vi har tillid til Kommissionen, til Romano Prodi, og flertallet i vores gruppe har udtrykt tillid til Romano Prodi og Kommissionen efter en vanskelig proces, som alle kender til. Men vi mener ogsÃ¥, at vi skal have en debat om Kommissionens strategi i en ordinær procedure, ikke kun pÃ¥ baggrund af en mundtlig forklaring her i Europa-Parlamentet, men ogsÃ¥ pÃ¥ baggrund af et dokument, som er blevet besluttet i Kommissionen, og som beskriver dette program for fem Ã¥r. Et sÃ¥dant dokument findes ikke! + +Kommissionen vil fremlægge programmet for Ã¥r 2000 til februar. Vi har sagt, at hvis Kommissionen ikke ønsker at lave programmet for Ã¥r 2000 i januar, sÃ¥ gør vi det i februar. Det har vi godkendt. Vi ønsker sÃ¥dan set ikke nogen konflikt med Kommissionen, vi mener derimod, at hvis det gÃ¥r, skal Kommissionen og Parlamentet gÃ¥ samme vej. Men Parlamentet er ogsÃ¥ Kommissionens kontrollør. Og ikke alt, hvad der kommer fra Kommissionen, skal nødvendigvis være i overensstemmelse med os. +Jeg vil gerne have, at vi fÃ¥r mulighed for at forberede os fornuftigt pÃ¥ en debat om femÃ¥rsprogrammet i grupperne. Man kan ikke forberede sig, hvis man hører en forklaring her og slet ikke ved, hvad indholdet af en sÃ¥dan forklaring er. Derfor anbefaler vi - og det er mit indtryk, at Kommissionen ogsÃ¥ er Ã¥ben over for denne tanke - at vi fører debatten om Kommissionens langsigtede program frem til Ã¥r 2005 i februar - jeg hÃ¥ber ogsÃ¥, at Kommissionen er blevet enig om et program til den tid, som den vil foreslÃ¥ os - og at vi samtidig fører en debat om Kommissionens lovgivningsprogram for Ã¥r 2000 i februar. Det er sÃ¥ledes ogsÃ¥ en fornuftig saglig sammenhæng, som rÃ¥der os til at føre debatten om begge programmer i fællesskab. Derfor afviser min gruppe pÃ¥ det bestemteste Den Socialdemokratiske Gruppes forslag! +(Bifald fra PPE-DE-gruppen) + +Fru formand, jeg vil gøre det meget klart, at Kommissionen først og fremmest har den største respekt for Parlamentets beslutninger, deriblandt opstillingen af dagsordenen. Derfor respekterer vi Parlamentets beslutning, hvad det angÃ¥r. +Men jeg vil ogsÃ¥ gøre det meget klart, at hr. Prodi aftalte med Parlamentet at indføre en ny forhandling, som hr. Barón nok husker, ud over den Ã¥rlige forhandling om Kommissionens lovgivningsprogram, om hovedlinjerne i aktionerne for den kommende femÃ¥rsperiode, altsÃ¥ for denne valgperiode. +Jeg vil sige, fru formand, at denne forhandling i den aftale, som blev indgÃ¥et i september, adskilte sig fra Kommissionens Ã¥rlige forelæggelse af programmet for lovgivningen. Og jeg vil sige, fru formand, at vi i Kommissionen er forberedt pÃ¥ og rede til at deltage i den forhandling, nÃ¥r det er belejligt, at vi var rede til at gennemføre den i denne uge, som det var aftalt fra begyndelsen, med udgangspunkt i at den blev forelagt dagen før i en tale til de parlamentariske grupper. +Jeg vil derfor gentage, fru formand, at vi for vores del har diskuteret handlingsprogrammet for de kommende fem Ã¥r, og at vi er rede til, nÃ¥r Parlamentet bestemmer det - i denne uge, hvis det er beslutningen - at komme og forelægge programmet for de kommende fem Ã¥r og i næste mÃ¥ned programmet for 2000, hvilket er helt i overensstemmelse med aftalen. + +Jeg foreslÃ¥r, at vi stemmer om PSE-gruppens anmodning om at fÃ¥ en redegørelse fra Kommissionen om dens strategiske mÃ¥l genopført pÃ¥ dagsordenen. +(Forslaget forkastedes) Formanden. Stadig med hensyn til dagsordenen for onsdag har jeg et forslag om de mundtlige forespørgsler om kapitalskat. PPE-DE-gruppen ønsker, at dette punkt tages af dagsordenen. +Ãnsker nogen at tage ordet pÃ¥ vegne af gruppen for at begrunde denne anmodning? + +Fru formand, da jeg kan høre en smule latter fra Socialdemokraterne - jeg har fÃ¥et fortalt, at brede kredse i Den Socialdemokratiske Gruppe ogsÃ¥ gerne vil have taget dette punkt af dagsordenen, fordi der ved afstemningen pÃ¥ Formandskonferencen ikke forelÃ¥ noget votum fra arbejdsgruppen af ansvarlige kolleger i Den Socialdemokratiske Gruppe. Jeg ved ikke, om denne oplysning er rigtig, men PPE-DE-gruppen ville i hvert fald være taknemmelig, hvis dette punkt blev annulleret, fordi Parlamentet allerede har beskæftiget sig med dette spørgsmÃ¥l flere gange. Der er ogsÃ¥ truffet beslutninger mod en sÃ¥dan skat. Derfor anmoder min gruppe om, at dette punkt tages af dagsordenen. + +Tak, hr. Poettering. +Vi skal nu høre hr. Wurtz, der er imod forslaget. + +Fru formand, jeg vil først og fremmest fremhæve hr. Poetterings manglende konsekvens. For et øjeblik siden belærte han socialdemokraterne, fordi de ville ændre en klar beslutning truffet pÃ¥ Formandskonferencen. Imidlertid gør han det samme. Vi havde en diskussion, vi var alle - pÃ¥ nær PPE-DE-gruppen og Den Liberale Gruppe - enige, og jeg bemærkede endda - som De sikkert husker, kære medformænd - at det ikke drejede sig om, hvorvidt De er for eller imod Tobin-afgiften, men om De turde høre, hvad Kommissionen og RÃ¥det mente om den. Dette er ikke for meget forlangt. Derfor fastholder jeg forslaget om at bevare det mundtlige spørgsmÃ¥l til Kommissionen og RÃ¥det, sÃ¥ledes at vi én gang for alle fÃ¥r opklaret, hvilken holdning de to institutioner har til dette ret beskedne forslag, som dog sender et vigtigt signal til befolkningen, navnlig efter fiaskoen i Seattle. + +Vi skal stemme om PPE-DE-gruppens anmodning om, at de mundtlige forespørgsler om kapitalskat tages af dagsordenen. +(Forslaget forkastedes. 164 stemte for, 166 stemte imod, og 7 undlod at stemme) + +Fru formand, jeg vil gerne takke hr. Poettering for den reklame, han netop har gjort for denne debat. Tak. + +Fru formand, er min stemme, som jeg ikke kunne afgive elektronisk, fordi jeg ikke har kortet, blevet talt med? Jeg stemte for. + +Det er rigtigt. Hvis vi tilføjer de to kolleger, der har givet sig til kende, bliver resultatet ... + +Fru formand, formandskabet har bekendtgjort afstemningens udfald. Det kan der ikke laves om pÃ¥. + +Kære kolleger, jeg minder endnu en gang om, at det er vigtigt, at alle har deres kort om mandagen. Det er tydeligt, at vi har et problem, og jeg mÃ¥ derfor træffe en beslutning. +Jeg har ogsÃ¥ glemt mit kort, og jeg ville have stemt imod. Derfor mener jeg, at det mundtlige spørgsmÃ¥l fortsat skal medtages pÃ¥ dagsordenen. +Det er sidste gang, vi vil tage hensyn til glemte kort. Lad dette være helt klart, og husk det. +(Bifald) +Ja, det mundtlige spørgsmÃ¥l er fortsat opført pÃ¥ dagsordenen, og ja, formanden har ret til at stemme, ligesom hun har ret til at glemme sit kort. +Vi fortsætter nu med de øvrige ændringer af dagsordenen. + +Fru formand, i den tidligere afstemning - og jeg vil rette mig efter Deres afgørelse om dette emne - om spørgsmÃ¥let om Kommissionens redegørelse om dens strategiske mÃ¥l gav jeg udtryk for, at jeg gerne ville tale pÃ¥ vegne af min gruppe før afstemningen. Det blev ikke til noget. Jeg vil sætte pris pÃ¥ at fÃ¥ lejlighed til at afgive stemmeforklaring pÃ¥ vegne af min gruppe i forbindelse med afslutningen af dette spørgsmÃ¥l. Det er et vigtigt spørgsmÃ¥l, og det vil være nyttigt for Parlamentet, hvis det er angivet, hvordan de forskellige personer opfatter vores handlinger i lyset af deres egne politiske analyser. + +Fru formand, jeg vil ikke genoptage debatten, men jeg havde ogsÃ¥ meldt mig for at tage stilling til hr. Barón Crespos ændringsforslag. De rÃ¥bte mig heller ikke op. Det beklager jeg, men afstemningen er gennemført, afgørelsen er truffet, vi lader det altsÃ¥ ligge. + +Jeg beklager, hr. Hänsch og hr. Cox, jeg sÃ¥ ikke, at De anmodede om ordet. Men i øvrigt mener jeg, at holdningerne er meget klare, og de vil blive indført i protokollen. NÃ¥r vi i morgen skal vedtage protokollen for i dag, kan de kolleger, der ikke synes, at holdningerne er blevet tilstrækkeligt forklaret, anmode om ændringer. Det, mener jeg, er en god løsning. Selvfølgelig vil protokollen for mødet i morgen tage hensyn til alle de supplerende forklaringer. Jeg mener, at det er en bedre løsning end at gÃ¥ over til stemmeforklaringer pÃ¥ nuværende tidspunkt, som ville være et stort sidespring. Hr. Cox og hr. Hänsch, passer denne løsning Dem? + +Fru formand, hvis protokollen giver korrekt udtryk for min gruppes holdning i forbindelse med afstemningen, vil og kan jeg ikke gøre indsigelser. Hvis De afgør, at der ikke er grund til at afgive stemmeforklaring, vil jeg acceptere det, men med forbehold. + +Vi vil derfor være meget opmærksomme pÃ¥ udarbejdelsen af protokollen. Det er vi i øvrigt altid. Hvis holdningerne ikke klart fremgÃ¥r, kan vi eventuelt ændre den. +(Den sÃ¥ledes ændrede dagsorden godkendtes) +
