Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

3088

3089

3090

3091

3092

3093

3094

3095

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3125

3126

3127

3128

3129

3130

3131

3132

3133

3134

3135

3136

3137

3138

3139

3140

3141

3142

3143

3144

3145

3146

3147

3148

3149

3150

3151

3152

3153

3154

3155

3156

3157

3158

3159

3160

3161

3162

3163

3164

3165

3166

3167

3168

3169

3170

3171

3172

3173

3174

3175

3176

3177

3178

3179

3180

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194

3195

3196

3197

3198

3199

3200

3201

3202

3203

3204

3205

3206

3207

3208

3209

3210

3211

3212

3213

3214

3215

3216

3217

3218

3219

3220

3221

3222

3223

3224

3225

3226

3227

3228

3229

3230

3231

3232

3233

3234

3235

3236

3237

3238

3239

3240

3241

3242

3243

3244

3245

3246

3247

3248

3249

3250

3251

3252

3253

3254

3255

3256

3257

3258

3259

3260

3261

3262

3263

3264

3265

3266

3267

3268

3269

3270

3271

3272

3273

3274

3275

3276

3277

3278

3279

3280

3281

3282

3283

3284

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3346

3347

3348

3349

3350

3351

3352

3353

3354

3355

3356

3357

3358

3359

3360

3361

3362

3363

3364

3365

3366

3367

3368

3369

3370

3371

3372

3373

3374

3375

3376

3377

3378

3379

3380

3381

3382

3383

3384

3385

3386

3387

3388

3389

3390

3391

3392

3393

3394

3395

3396

3397

3398

3399

3400

3401

3402

3403

3404

3405

3406

3407

3408

3409

3410

3411

3412

3413

3414

3415

3416

3417

3418

3419

3420

3421

3422

3423

3424

3425

3426

3427

3428

3429

3430

3431

3432

3433

3434

3435

3436

3437

3438

3439

3440

3441

3442

3443

3444

3445

3446

3447

3448

3449

3450

3451

3452

3453

3454

3455

3456

3457

3458

3459

3460

3461

3462

3463

3464

3465

3466

3467

3468

3469

3470

3471

3472

3473

3474

3475

3476

3477

3478

3479

3480

3481

3482

3483

3484

3485

3486

3487

3488

3489

3490

3491

3492

3493

3494

3495

3496

3497

3498

3499

3500

3501

3502

3503

3504

3505

3506

3507

3508

3509

3510

3511

3512

3513

3514

3515

3516

3517

3518

3519

3520

3521

3522

3523

3524

3525

3526

3527

3528

3529

3530

3531

3532

3533

3534

3535

3536

3537

3538

3539

3540

3541

3542

3543

3544

3545

3546

3547

3548

3549

3550

3551

3552

3553

3554

3555

3556

3557

3558

3559

3560

3561

3562

3563

3564

3565

3566

3567

3568

3569

3570

3571

3572

3573

3574

3575

3576

3577

3578

3579

3580

3581

3582

3583

3584

3585

3586

3587

3588

3589

3590

3591

3592

3593

3594

3595

3596

3597

3598

3599

3600

3601

3602

3603

3604

3605

3606

3607

3608

3609

3610

3611

3612

3613

3614

3615

3616

3617

3618

3619

3620

3621

3622

3623

3624

3625

3626

3627

3628

3629

3630

3631

3632

3633

3634

3635

3636

3637

3638

3639

3640

3641

3642

3643

3644

3645

3646

3647

3648

3649

3650

3651

3652

3653

3654

3655

3656

3657

3658

3659

3660

3661

3662

3663

3664

3665

3666

3667

3668

3669

3670

3671

3672

3673

3674

3675

3676

3677

3678

3679

3680

3681

3682

3683

3684

3685

3686

3687

3688

3689

3690

3691

3692

3693

3694

3695

3696

3697

3698

3699

3700

3701

3702

3703

3704

3705

3706

3707

3708

3709

3710

3711

3712

3713

3714

3715

3716

3717

3718

3719

3720

3721

3722

3723

3724

3725

3726

3727

3728

3729

3730

# -*- coding: utf-8 -*- 

# 

# Natural Language Toolkit: Snowball Stemmer 

# 

# Copyright (C) 2001-2012 NLTK Project 

# Author: Peter Michael Stahl <pemistahl@gmail.com> 

#         Peter Ljunglof <peter.ljunglof@heatherleaf.se> (revisions) 

# Algorithms: Dr Martin Porter <martin@tartarus.org> 

# URL: <http://www.nltk.org/> 

# For license information, see LICENSE.TXT 

 

""" 

Snowball stemmers and appendant demo function 

 

This module provides a port of the Snowball stemmers 

developed by Martin Porter. 

There is also a demo function demonstrating the different 

algorithms. It can be invoked directly on the command line. 

For more information take a look into the class SnowballStemmer. 

""" 

from __future__ import unicode_literals 

from __future__ import print_function 

 

from nltk.corpus import stopwords 

from nltk.stem import porter 

 

from .api import StemmerI 

 

class SnowballStemmer(StemmerI): 

 

    """ 

    Snowball Stemmer 

 

    At the moment, this port is able to stem words from fourteen 

    languages: Danish, Dutch, English, Finnish, French, German, 

    Hungarian, Italian, Norwegian, Portuguese, Romanian, Russian, 

    Spanish and Swedish. 

 

    Furthermore, there is also the original English Porter algorithm: 

 

        Porter, M. \"An algorithm for suffix stripping.\" 

        Program 14.3 (1980): 130-137. 

 

    The algorithms have been developed by Martin Porter. 

    These stemmers are called Snowball, because he invented 

    a programming language with this name for creating 

    new stemming algorithms. There is more information available 

    at http://snowball.tartarus.org/ 

 

    The stemmer is invoked as shown below: 

 

    >>> from nltk.stem import SnowballStemmer 

    >>> print(" ".join(SnowballStemmer.languages)) # See which languages are supported 

    danish dutch english finnish french german hungarian 

    italian norwegian porter portuguese romanian russian 

    spanish swedish 

    >>> stemmer = SnowballStemmer("german") # Choose a language 

    >>> stemmer.stem(u"Autobahnen") # Stem a word 

    u'autobahn' 

 

    Invoking the stemmers that way is useful if you do not know the 

    language to be stemmed at runtime. Alternatively, if you already know 

    the language, then you can invoke the language specific stemmer directly: 

 

    >>> from nltk.stem.snowball import GermanStemmer 

    >>> stemmer = GermanStemmer() 

    >>> stemmer.stem(u"Autobahnen") 

    u'autobahn' 

 

    Create a language specific instance of the Snowball stemmer. 

 

    :param language: The language whose subclass is instantiated. 

    :type language: str or unicode 

    :param ignore_stopwords: If set to True, stopwords are 

                             not stemmed and returned unchanged. 

                             Set to False by default. 

    :type ignore_stopwords: bool 

    :raise ValueError: If there is no stemmer for the specified 

                           language, a ValueError is raised. 

    """ 

 

    languages = ("danish", "dutch", "english", "finnish", "french", "german", 

                 "hungarian", "italian", "norwegian", "porter", "portuguese", 

                 "romanian", "russian", "spanish", "swedish") 

 

    def __init__(self, language, ignore_stopwords=False): 

        if language not in self.languages: 

            raise ValueError("The language '%s' is not supported." % language) 

        stemmerclass = globals()[language.capitalize() + "Stemmer"] 

        self.stemmer = stemmerclass(ignore_stopwords) 

        self.stem = self.stemmer.stem 

        self.stopwords = self.stemmer.stopwords 

 

 

class _LanguageSpecificStemmer(StemmerI): 

 

    """ 

    This helper subclass offers the possibility 

    to invoke a specific stemmer directly. 

    This is useful if you already know the language to be stemmed at runtime. 

 

    Create an instance of the Snowball stemmer. 

 

    :param ignore_stopwords: If set to True, stopwords are 

                             not stemmed and returned unchanged. 

                             Set to False by default. 

    :type ignore_stopwords: bool 

    """ 

 

    def __init__(self, ignore_stopwords=False): 

        # The language is the name of the class, minus the final "Stemmer". 

        language = type(self).__name__.lower() 

        if language.endswith("stemmer"): 

            language = language[:-7] 

 

        self.stopwords = set() 

        if ignore_stopwords: 

            try: 

                for word in stopwords.words(language): 

                    self.stopwords.add(word.decode("utf-8")) 

            except IOError: 

                raise ValueError("%r has no list of stopwords. Please set" 

                                 " 'ignore_stopwords' to 'False'." % self) 

 

    def __repr__(self): 

        """ 

        Print out the string representation of the respective class. 

 

        """ 

        return "<%s>" % type(self).__name__ 

 

 

class PorterStemmer(_LanguageSpecificStemmer, porter.PorterStemmer): 

    """ 

    A word stemmer based on the original Porter stemming algorithm. 

 

        Porter, M. \"An algorithm for suffix stripping.\" 

        Program 14.3 (1980): 130-137. 

 

    A few minor modifications have been made to Porter's basic 

    algorithm.  See the source code of the module 

    nltk.stem.porter for more information. 

 

    """ 

    def __init__(self, ignore_stopwords=False): 

        _LanguageSpecificStemmer.__init__(self, ignore_stopwords) 

        porter.PorterStemmer.__init__(self) 

 

 

class _ScandinavianStemmer(_LanguageSpecificStemmer): 

 

    """ 

    This subclass encapsulates a method for defining the string region R1. 

    It is used by the Danish, Norwegian, and Swedish stemmer. 

 

    """ 

 

    def _r1_scandinavian(self, word, vowels): 

        """ 

        Return the region R1 that is used by the Scandinavian stemmers. 

 

        R1 is the region after the first non-vowel following a vowel, 

        or is the null region at the end of the word if there is no 

        such non-vowel. But then R1 is adjusted so that the region 

        before it contains at least three letters. 

 

        :param word: The word whose region R1 is determined. 

        :type word: str or unicode 

        :param vowels: The vowels of the respective language that are 

                       used to determine the region R1. 

        :type vowels: unicode 

        :return: the region R1 for the respective word. 

        :rtype: unicode 

        :note: This helper method is invoked by the respective stem method of 

               the subclasses DanishStemmer, NorwegianStemmer, and 

               SwedishStemmer. It is not to be invoked directly! 

 

        """ 

        r1 = "" 

        for i in range(1, len(word)): 

            if word[i] not in vowels and word[i-1] in vowels: 

                if len(word[:i+1]) < 3 and len(word[:i+1]) > 0: 

                    r1 = word[3:] 

                elif len(word[:i+1]) >= 3: 

                    r1 = word[i+1:] 

                else: 

                    return word 

                break 

 

        return r1 

 

 

 

class _StandardStemmer(_LanguageSpecificStemmer): 

 

    """ 

    This subclass encapsulates two methods for defining the standard versions 

    of the string regions R1, R2, and RV. 

 

    """ 

 

    def _r1r2_standard(self, word, vowels): 

        """ 

        Return the standard interpretations of the string regions R1 and R2. 

 

        R1 is the region after the first non-vowel following a vowel, 

        or is the null region at the end of the word if there is no 

        such non-vowel. 

 

        R2 is the region after the first non-vowel following a vowel 

        in R1, or is the null region at the end of the word if there 

        is no such non-vowel. 

 

        :param word: The word whose regions R1 and R2 are determined. 

        :type word: str or unicode 

        :param vowels: The vowels of the respective language that are 

                       used to determine the regions R1 and R2. 

        :type vowels: unicode 

        :return: (r1,r2), the regions R1 and R2 for the respective word. 

        :rtype: tuple 

        :note: This helper method is invoked by the respective stem method of 

               the subclasses DutchStemmer, FinnishStemmer, 

               FrenchStemmer, GermanStemmer, ItalianStemmer, 

               PortugueseStemmer, RomanianStemmer, and SpanishStemmer. 

               It is not to be invoked directly! 

        :note: A detailed description of how to define R1 and R2 

               can be found at http://snowball.tartarus.org/texts/r1r2.html 

 

        """ 

        r1 = "" 

        r2 = "" 

        for i in range(1, len(word)): 

            if word[i] not in vowels and word[i-1] in vowels: 

                r1 = word[i+1:] 

                break 

 

        for i in range(1, len(r1)): 

            if r1[i] not in vowels and r1[i-1] in vowels: 

                r2 = r1[i+1:] 

                break 

 

        return (r1, r2) 

 

 

 

    def _rv_standard(self, word, vowels): 

        """ 

        Return the standard interpretation of the string region RV. 

 

        If the second letter is a consonant, RV is the region after the 

        next following vowel. If the first two letters are vowels, RV is 

        the region after the next following consonant. Otherwise, RV is 

        the region after the third letter. 

 

        :param word: The word whose region RV is determined. 

        :type word: str or unicode 

        :param vowels: The vowels of the respective language that are 

                       used to determine the region RV. 

        :type vowels: unicode 

        :return: the region RV for the respective word. 

        :rtype: unicode 

        :note: This helper method is invoked by the respective stem method of 

               the subclasses ItalianStemmer, PortugueseStemmer, 

               RomanianStemmer, and SpanishStemmer. It is not to be 

               invoked directly! 

 

        """ 

        rv = "" 

        if len(word) >= 2: 

            if word[1] not in vowels: 

                for i in range(2, len(word)): 

                    if word[i] in vowels: 

                        rv = word[i+1:] 

                        break 

 

            elif word[:2] in vowels: 

                for i in range(2, len(word)): 

                    if word[i] not in vowels: 

                        rv = word[i+1:] 

                        break 

            else: 

                rv = word[3:] 

 

        return rv 

 

 

 

class DanishStemmer(_ScandinavianStemmer): 

 

    """ 

    The Danish Snowball stemmer. 

 

    :cvar __vowels: The Danish vowels. 

    :type __vowels: unicode 

    :cvar __consonants: The Danish consonants. 

    :type __consonants: unicode 

    :cvar __double_consonants: The Danish double consonants. 

    :type __double_consonants: tuple 

    :cvar __s_ending: Letters that may directly appear before a word final 's'. 

    :type __s_ending: unicode 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :note: A detailed description of the Danish 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/danish/stemmer.html 

 

    """ 

 

    # The language's vowels and other important characters are defined. 

    __vowels = "aeiouy\xE6\xE5\xF8" 

    __consonants = "bcdfghjklmnpqrstvwxz" 

    __double_consonants = ("bb", "cc", "dd", "ff", "gg", "hh", "jj", 

                           "kk", "ll", "mm", "nn", "pp", "qq", "rr", 

                           "ss", "tt", "vv", "ww", "xx", "zz") 

    __s_ending = "abcdfghjklmnoprtvyz\xE5" 

 

    # The different suffixes, divided into the algorithm's steps 

    # and organized by length, are listed in tuples. 

    __step1_suffixes = ("erendes", "erende", "hedens", "ethed", 

                        "erede", "heden", "heder", "endes", 

                        "ernes", "erens", "erets", "ered", 

                        "ende", "erne", "eren", "erer", "heds", 

                        "enes", "eres", "eret", "hed", "ene", "ere", 

                        "ens", "ers", "ets", "en", "er", "es", "et", 

                        "e", "s") 

    __step2_suffixes = ("gd", "dt", "gt", "kt") 

    __step3_suffixes = ("elig", "l\xF8st", "lig", "els", "ig") 

 

    def stem(self, word): 

        """ 

        Stem a Danish word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        # Every word is put into lower case for normalization. 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        # After this, the required regions are generated 

        # by the respective helper method. 

        r1 = self._r1_scandinavian(word, self.__vowels) 

 

        # Then the actual stemming process starts. 

        # Every new step is explicitly indicated 

        # according to the descriptions on the Snowball website. 

 

        # STEP 1 

        for suffix in self.__step1_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "s": 

                    if word[-2] in self.__s_ending: 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                break 

 

        # STEP 2 

        for suffix in self.__step2_suffixes: 

            if r1.endswith(suffix): 

                word = word[:-1] 

                r1 = r1[:-1] 

                break 

 

        # STEP 3 

        if r1.endswith("igst"): 

            word = word[:-2] 

            r1 = r1[:-2] 

 

        for suffix in self.__step3_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "l\xF8st": 

                    word = word[:-1] 

                    r1 = r1[:-1] 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

 

                    if r1.endswith(self.__step2_suffixes): 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                break 

 

        # STEP 4: Undouble 

        for double_cons in self.__double_consonants: 

            if word.endswith(double_cons) and len(word) > 3: 

                word = word[:-1] 

                break 

 

 

        return word 

 

 

 

 

class DutchStemmer(_StandardStemmer): 

 

    """ 

    The Dutch Snowball stemmer. 

 

    :cvar __vowels: The Dutch vowels. 

    :type __vowels: unicode 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step3b_suffixes: Suffixes to be deleted in step 3b of the algorithm. 

    :type __step3b_suffixes: tuple 

    :note: A detailed description of the Dutch 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/dutch/stemmer.html 

 

    """ 

 

    __vowels = "aeiouy\xE8" 

    __step1_suffixes = ("heden", "ene", "en", "se", "s") 

    __step3b_suffixes = ("baar", "lijk", "bar", "end", "ing", "ig") 

 

    def stem(self, word): 

        """ 

        Stem a Dutch word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        step2_success = False 

 

        # Vowel accents are removed. 

        word = (word.replace("\xE4", "a").replace("\xE1", "a") 

                    .replace("\xEB", "e").replace("\xE9", "e") 

                    .replace("\xED", "i").replace("\xEF", "i") 

                    .replace("\xF6", "o").replace("\xF3", "o") 

                    .replace("\xFC", "u").replace("\xFA", "u")) 

 

        # An initial 'y', a 'y' after a vowel, 

        # and an 'i' between self.__vowels is put into upper case. 

        # As from now these are treated as consonants. 

        if word.startswith("y"): 

            word = "".join(("Y", word[1:])) 

 

        for i in range(1, len(word)): 

            if word[i-1] in self.__vowels and word[i] == "y": 

                word = "".join((word[:i], "Y", word[i+1:])) 

 

        for i in range(1, len(word)-1): 

            if (word[i-1] in self.__vowels and word[i] == "i" and 

               word[i+1] in self.__vowels): 

                word = "".join((word[:i], "I", word[i+1:])) 

 

        r1, r2 = self._r1r2_standard(word, self.__vowels) 

 

        # R1 is adjusted so that the region before it 

        # contains at least 3 letters. 

        for i in range(1, len(word)): 

            if word[i] not in self.__vowels and word[i-1] in self.__vowels: 

                if len(word[:i+1]) < 3 and len(word[:i+1]) > 0: 

                    r1 = word[3:] 

                elif len(word[:i+1]) == 0: 

                    return word 

                break 

 

        # STEP 1 

        for suffix in self.__step1_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "heden": 

                    word = "".join((word[:-5], "heid")) 

                    r1 = "".join((r1[:-5], "heid")) 

                    if r2.endswith("heden"): 

                        r2 = "".join((r2[:-5], "heid")) 

 

                elif (suffix in ("ene", "en") and 

                      not word.endswith("heden") and 

                      word[-len(suffix)-1] not in self.__vowels and 

                      word[-len(suffix)-3:-len(suffix)] != "gem"): 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                    if word.endswith(("kk", "dd", "tt")): 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                        r2 = r2[:-1] 

 

                elif (suffix in ("se", "s") and 

                      word[-len(suffix)-1] not in self.__vowels and 

                      word[-len(suffix)-1] != "j"): 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                break 

 

        # STEP 2 

        if r1.endswith("e") and word[-2] not in self.__vowels: 

            step2_success = True 

            word = word[:-1] 

            r1 = r1[:-1] 

            r2 = r2[:-1] 

 

            if word.endswith(("kk", "dd", "tt")): 

                word = word[:-1] 

                r1 = r1[:-1] 

                r2 = r2[:-1] 

 

        # STEP 3a 

        if r2.endswith("heid") and word[-5] != "c": 

            word = word[:-4] 

            r1 = r1[:-4] 

            r2 = r2[:-4] 

 

            if (r1.endswith("en") and word[-3] not in self.__vowels and 

                word[-5:-2] != "gem"): 

                word = word[:-2] 

                r1 = r1[:-2] 

                r2 = r2[:-2] 

 

                if word.endswith(("kk", "dd", "tt")): 

                    word = word[:-1] 

                    r1 = r1[:-1] 

                    r2 = r2[:-1] 

 

        # STEP 3b: Derivational suffixes 

        for suffix in self.__step3b_suffixes: 

            if r2.endswith(suffix): 

                if suffix in ("end", "ing"): 

                    word = word[:-3] 

                    r2 = r2[:-3] 

 

                    if r2.endswith("ig") and word[-3] != "e": 

                        word = word[:-2] 

                    else: 

                        if word.endswith(("kk", "dd", "tt")): 

                            word = word[:-1] 

 

                elif suffix == "ig" and word[-3] != "e": 

                    word = word[:-2] 

 

                elif suffix == "lijk": 

                    word = word[:-4] 

                    r1 = r1[:-4] 

 

                    if r1.endswith("e") and word[-2] not in self.__vowels: 

                        word = word[:-1] 

                        if word.endswith(("kk", "dd", "tt")): 

                            word = word[:-1] 

 

                elif suffix == "baar": 

                    word = word[:-4] 

 

                elif suffix == "bar" and step2_success: 

                    word = word[:-3] 

                break 

 

        # STEP 4: Undouble vowel 

        if len(word) >= 4: 

            if word[-1] not in self.__vowels and word[-1] != "I": 

                if word[-3:-1] in ("aa", "ee", "oo", "uu"): 

                    if word[-4] not in self.__vowels: 

                        word = "".join((word[:-3], word[-3], word[-1])) 

 

        # All occurrences of 'I' and 'Y' are put back into lower case. 

        word = word.replace("I", "i").replace("Y", "y") 

 

 

        return word 

 

 

 

class EnglishStemmer(_StandardStemmer): 

 

    """ 

    The English Snowball stemmer. 

 

    :cvar __vowels: The English vowels. 

    :type __vowels: unicode 

    :cvar __double_consonants: The English double consonants. 

    :type __double_consonants: tuple 

    :cvar __li_ending: Letters that may directly appear before a word final 'li'. 

    :type __li_ending: unicode 

    :cvar __step0_suffixes: Suffixes to be deleted in step 0 of the algorithm. 

    :type __step0_suffixes: tuple 

    :cvar __step1a_suffixes: Suffixes to be deleted in step 1a of the algorithm. 

    :type __step1a_suffixes: tuple 

    :cvar __step1b_suffixes: Suffixes to be deleted in step 1b of the algorithm. 

    :type __step1b_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :cvar __step4_suffixes: Suffixes to be deleted in step 4 of the algorithm. 

    :type __step4_suffixes: tuple 

    :cvar __step5_suffixes: Suffixes to be deleted in step 5 of the algorithm. 

    :type __step5_suffixes: tuple 

    :cvar __special_words: A dictionary containing words 

                           which have to be stemmed specially. 

    :type __special_words: dict 

    :note: A detailed description of the English 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/english/stemmer.html 

    """ 

 

    __vowels = "aeiouy" 

    __double_consonants = ("bb", "dd", "ff", "gg", "mm", "nn", 

                           "pp", "rr", "tt") 

    __li_ending = "cdeghkmnrt" 

    __step0_suffixes = ("'s'", "'s", "'") 

    __step1a_suffixes = ("sses", "ied", "ies", "us", "ss", "s") 

    __step1b_suffixes = ("eedly", "ingly", "edly", "eed", "ing", "ed") 

    __step2_suffixes = ('ization', 'ational', 'fulness', 'ousness', 

                        'iveness', 'tional', 'biliti', 'lessli', 

                        'entli', 'ation', 'alism', 'aliti', 'ousli', 

                        'iviti', 'fulli', 'enci', 'anci', 'abli', 

                        'izer', 'ator', 'alli', 'bli', 'ogi', 'li') 

    __step3_suffixes = ('ational', 'tional', 'alize', 'icate', 'iciti', 

                        'ative', 'ical', 'ness', 'ful') 

    __step4_suffixes = ('ement', 'ance', 'ence', 'able', 'ible', 'ment', 

                        'ant', 'ent', 'ism', 'ate', 'iti', 'ous', 

                        'ive', 'ize', 'ion', 'al', 'er', 'ic') 

    __step5_suffixes = ("e", "l") 

    __special_words = {"skis" : "ski", 

                       "skies" : "sky", 

                       "dying" : "die", 

                       "lying" : "lie", 

                       "tying" : "tie", 

                       "idly" : "idl", 

                       "gently" : "gentl", 

                       "ugly" : "ugli", 

                       "early" : "earli", 

                       "only" : "onli", 

                       "singly" : "singl", 

                       "sky" : "sky", 

                       "news" : "news", 

                       "howe" : "howe", 

                       "atlas" : "atlas", 

                       "cosmos" : "cosmos", 

                       "bias" : "bias", 

                       "andes" : "andes", 

                       "inning" : "inning", 

                       "innings" : "inning", 

                       "outing" : "outing", 

                       "outings" : "outing", 

                       "canning" : "canning", 

                       "cannings" : "canning", 

                       "herring" : "herring", 

                       "herrings" : "herring", 

                       "earring" : "earring", 

                       "earrings" : "earring", 

                       "proceed" : "proceed", 

                       "proceeds" : "proceed", 

                       "proceeded" : "proceed", 

                       "proceeding" : "proceed", 

                       "exceed" : "exceed", 

                       "exceeds" : "exceed", 

                       "exceeded" : "exceed", 

                       "exceeding" : "exceed", 

                       "succeed" : "succeed", 

                       "succeeds" : "succeed", 

                       "succeeded" : "succeed", 

                       "succeeding" : "succeed"} 

 

    def stem(self, word): 

 

        """ 

        Stem an English word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords or len(word) <= 2: 

            return word 

 

        elif word in self.__special_words: 

            return self.__special_words[word] 

 

        # Map the different apostrophe characters to a single consistent one 

        word = (word.replace("\u2019", "\x27") 

                    .replace("\u2018", "\x27") 

                    .replace("\u201B", "\x27")) 

 

        if word.startswith("\x27"): 

            word = word[1:] 

 

        if word.startswith("y"): 

            word = "".join(("Y", word[1:])) 

 

        for i in range(1, len(word)): 

            if word[i-1] in self.__vowels and word[i] == "y": 

                word = "".join((word[:i], "Y", word[i+1:])) 

 

        step1a_vowel_found = False 

        step1b_vowel_found = False 

 

        r1 = "" 

        r2 = "" 

 

        if word.startswith(("gener", "commun", "arsen")): 

            if word.startswith(("gener", "arsen")): 

                r1 = word[5:] 

            else: 

                r1 = word[6:] 

 

            for i in range(1, len(r1)): 

                if r1[i] not in self.__vowels and r1[i-1] in self.__vowels: 

                    r2 = r1[i+1:] 

                    break 

        else: 

            r1, r2 = self._r1r2_standard(word, self.__vowels) 

 

 

        # STEP 0 

        for suffix in self.__step0_suffixes: 

            if word.endswith(suffix): 

                word = word[:-len(suffix)] 

                r1 = r1[:-len(suffix)] 

                r2 = r2[:-len(suffix)] 

                break 

 

        # STEP 1a 

        for suffix in self.__step1a_suffixes: 

            if word.endswith(suffix): 

 

                if suffix == "sses": 

                    word = word[:-2] 

                    r1 = r1[:-2] 

                    r2 = r2[:-2] 

 

                elif suffix in ("ied", "ies"): 

                    if len(word[:-len(suffix)]) > 1: 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

                    else: 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                        r2 = r2[:-1] 

 

                elif suffix == "s": 

                    for letter in word[:-2]: 

                        if letter in self.__vowels: 

                            step1a_vowel_found = True 

                            break 

 

                    if step1a_vowel_found: 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                        r2 = r2[:-1] 

                break 

 

        # STEP 1b 

        for suffix in self.__step1b_suffixes: 

            if word.endswith(suffix): 

                if suffix in ("eed", "eedly"): 

 

                    if r1.endswith(suffix): 

                        word = "".join((word[:-len(suffix)], "ee")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "ee")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "ee")) 

                        else: 

                            r2 = "" 

                else: 

                    for letter in word[:-len(suffix)]: 

                        if letter in self.__vowels: 

                            step1b_vowel_found = True 

                            break 

 

                    if step1b_vowel_found: 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

 

                        if word.endswith(("at", "bl", "iz")): 

                            word = "".join((word, "e")) 

                            r1 = "".join((r1, "e")) 

 

                            if len(word) > 5 or len(r1) >=3: 

                                r2 = "".join((r2, "e")) 

 

                        elif word.endswith(self.__double_consonants): 

                            word = word[:-1] 

                            r1 = r1[:-1] 

                            r2 = r2[:-1] 

 

                        elif ((r1 == "" and len(word) >= 3 and 

                               word[-1] not in self.__vowels and 

                               word[-1] not in "wxY" and 

                               word[-2] in self.__vowels and 

                               word[-3] not in self.__vowels) 

                              or 

                              (r1 == "" and len(word) == 2 and 

                               word[0] in self.__vowels and 

                               word[1] not in self.__vowels)): 

 

                            word = "".join((word, "e")) 

 

                            if len(r1) > 0: 

                                r1 = "".join((r1, "e")) 

 

                            if len(r2) > 0: 

                                r2 = "".join((r2, "e")) 

                break 

 

        # STEP 1c 

        if word[-1] in "yY" and word[-2] not in self.__vowels and len(word) > 2: 

            word = "".join((word[:-1], "i")) 

            if len(r1) >= 1: 

                r1 = "".join((r1[:-1], "i")) 

            else: 

                r1 = "" 

 

            if len(r2) >= 1: 

                r2 = "".join((r2[:-1], "i")) 

            else: 

                r2 = "" 

 

        # STEP 2 

        for suffix in self.__step2_suffixes: 

            if word.endswith(suffix): 

                if r1.endswith(suffix): 

                    if suffix == "tional": 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

 

                    elif suffix in ("enci", "anci", "abli"): 

                        word = "".join((word[:-1], "e")) 

 

                        if len(r1) >= 1: 

                            r1 = "".join((r1[:-1], "e")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= 1: 

                            r2 = "".join((r2[:-1], "e")) 

                        else: 

                            r2 = "" 

 

                    elif suffix == "entli": 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

 

                    elif suffix in ("izer", "ization"): 

                        word = "".join((word[:-len(suffix)], "ize")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "ize")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "ize")) 

                        else: 

                            r2 = "" 

 

                    elif suffix in ("ational", "ation", "ator"): 

                        word = "".join((word[:-len(suffix)], "ate")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "ate")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "ate")) 

                        else: 

                            r2 = "e" 

 

                    elif suffix in ("alism", "aliti", "alli"): 

                        word = "".join((word[:-len(suffix)], "al")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "al")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "al")) 

                        else: 

                            r2 = "" 

 

                    elif suffix == "fulness": 

                        word = word[:-4] 

                        r1 = r1[:-4] 

                        r2 = r2[:-4] 

 

                    elif suffix in ("ousli", "ousness"): 

                        word = "".join((word[:-len(suffix)], "ous")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "ous")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "ous")) 

                        else: 

                            r2 = "" 

 

                    elif suffix in ("iveness", "iviti"): 

                        word = "".join((word[:-len(suffix)], "ive")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "ive")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "ive")) 

                        else: 

                            r2 = "e" 

 

                    elif suffix in ("biliti", "bli"): 

                        word = "".join((word[:-len(suffix)], "ble")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "ble")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "ble")) 

                        else: 

                            r2 = "" 

 

                    elif suffix == "ogi" and word[-4] == "l": 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                        r2 = r2[:-1] 

 

                    elif suffix in ("fulli", "lessli"): 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

 

                    elif suffix == "li" and word[-3] in self.__li_ending: 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

                break 

 

        # STEP 3 

        for suffix in self.__step3_suffixes: 

            if word.endswith(suffix): 

                if r1.endswith(suffix): 

                    if suffix == "tional": 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

 

                    elif suffix == "ational": 

                        word = "".join((word[:-len(suffix)], "ate")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "ate")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "ate")) 

                        else: 

                            r2 = "" 

 

                    elif suffix == "alize": 

                        word = word[:-3] 

                        r1 = r1[:-3] 

                        r2 = r2[:-3] 

 

                    elif suffix in ("icate", "iciti", "ical"): 

                        word = "".join((word[:-len(suffix)], "ic")) 

 

                        if len(r1) >= len(suffix): 

                            r1 = "".join((r1[:-len(suffix)], "ic")) 

                        else: 

                            r1 = "" 

 

                        if len(r2) >= len(suffix): 

                            r2 = "".join((r2[:-len(suffix)], "ic")) 

                        else: 

                            r2 = "" 

 

                    elif suffix in ("ful", "ness"): 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

 

                    elif suffix == "ative" and r2.endswith(suffix): 

                        word = word[:-5] 

                        r1 = r1[:-5] 

                        r2 = r2[:-5] 

                break 

 

        # STEP 4 

        for suffix in self.__step4_suffixes: 

            if word.endswith(suffix): 

                if r2.endswith(suffix): 

                    if suffix == "ion": 

                        if word[-4] in "st": 

                            word = word[:-3] 

                            r1 = r1[:-3] 

                            r2 = r2[:-3] 

                    else: 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                break 

 

        # STEP 5 

        if r2.endswith("l") and word[-2] == "l": 

            word = word[:-1] 

        elif r2.endswith("e"): 

            word = word[:-1] 

        elif r1.endswith("e"): 

            if len(word) >= 4 and (word[-2] in self.__vowels or 

                                   word[-2] in "wxY" or 

                                   word[-3] not in self.__vowels or 

                                   word[-4] in self.__vowels): 

                word = word[:-1] 

 

 

        word = word.replace("Y", "y") 

 

 

        return word 

 

 

 

class FinnishStemmer(_StandardStemmer): 

 

    """ 

    The Finnish Snowball stemmer. 

 

    :cvar __vowels: The Finnish vowels. 

    :type __vowels: unicode 

    :cvar __restricted_vowels: A subset of the Finnish vowels. 

    :type __restricted_vowels: unicode 

    :cvar __long_vowels: The Finnish vowels in their long forms. 

    :type __long_vowels: tuple 

    :cvar __consonants: The Finnish consonants. 

    :type __consonants: unicode 

    :cvar __double_consonants: The Finnish double consonants. 

    :type __double_consonants: tuple 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :cvar __step4_suffixes: Suffixes to be deleted in step 4 of the algorithm. 

    :type __step4_suffixes: tuple 

    :note: A detailed description of the Finnish 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/finnish/stemmer.html 

    """ 

 

    __vowels = "aeiouy\xE4\xF6" 

    __restricted_vowels = "aeiou\xE4\xF6" 

    __long_vowels = ("aa", "ee", "ii", "oo", "uu", "\xE4\xE4", 

                     "\xF6\xF6") 

    __consonants = "bcdfghjklmnpqrstvwxz" 

    __double_consonants = ("bb", "cc", "dd", "ff", "gg", "hh", "jj", 

                           "kk", "ll", "mm", "nn", "pp", "qq", "rr", 

                           "ss", "tt", "vv", "ww", "xx", "zz") 

    __step1_suffixes = ('kaan', 'k\xE4\xE4n', 'sti', 'kin', 'han', 

                        'h\xE4n', 'ko', 'k\xF6', 'pa', 'p\xE4') 

    __step2_suffixes = ('nsa', 'ns\xE4', 'mme', 'nne', 'si', 'ni', 

                        'an', '\xE4n', 'en') 

    __step3_suffixes = ('siin', 'tten', 'seen', 'han', 'hen', 'hin', 

                        'hon', 'h\xE4n', 'h\xF6n', 'den', 'tta', 

                        'tt\xE4', 'ssa', 'ss\xE4', 'sta', 

                        'st\xE4', 'lla', 'll\xE4', 'lta', 

                        'lt\xE4', 'lle', 'ksi', 'ine', 'ta', 

                        't\xE4', 'na', 'n\xE4', 'a', '\xE4', 

                        'n') 

    __step4_suffixes = ('impi', 'impa', 'imp\xE4', 'immi', 'imma', 

                        'imm\xE4', 'mpi', 'mpa', 'mp\xE4', 'mmi', 

                        'mma', 'mm\xE4', 'eja', 'ej\xE4') 

 

    def stem(self, word): 

        """ 

        Stem a Finnish word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        step3_success = False 

 

        r1, r2 = self._r1r2_standard(word, self.__vowels) 

 

        # STEP 1: Particles etc. 

        for suffix in self.__step1_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "sti": 

                    if suffix in r2: 

                        word = word[:-3] 

                        r1 = r1[:-3] 

                        r2 = r2[:-3] 

                else: 

                    if word[-len(suffix)-1] in "ntaeiouy\xE4\xF6": 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                break 

 

        # STEP 2: Possessives 

        for suffix in self.__step2_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "si": 

                    if word[-3] != "k": 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

 

                elif suffix == "ni": 

                    word = word[:-2] 

                    r1 = r1[:-2] 

                    r2 = r2[:-2] 

                    if word.endswith("kse"): 

                        word = "".join((word[:-3], "ksi")) 

 

                    if r1.endswith("kse"): 

                        r1 = "".join((r1[:-3], "ksi")) 

 

                    if r2.endswith("kse"): 

                        r2 = "".join((r2[:-3], "ksi")) 

 

                elif suffix == "an": 

                    if (word[-4:-2] in ("ta", "na") or 

                        word[-5:-2] in ("ssa", "sta", "lla", "lta")): 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

 

                elif suffix == "\xE4n": 

                    if (word[-4:-2] in ("t\xE4", "n\xE4") or 

                        word[-5:-2] in ("ss\xE4", "st\xE4", 

                                        "ll\xE4", "lt\xE4")): 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

 

                elif suffix == "en": 

                    if word[-5:-2] in ("lle", "ine"): 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

                else: 

                    word = word[:-3] 

                    r1 = r1[:-3] 

                    r2 = r2[:-3] 

                break 

 

        # STEP 3: Cases 

        for suffix in self.__step3_suffixes: 

            if r1.endswith(suffix): 

                if suffix in ("han", "hen", "hin", "hon", "h\xE4n", 

                              "h\xF6n"): 

                    if ((suffix == "han" and word[-4] == "a") or 

                        (suffix == "hen" and word[-4] == "e") or 

                        (suffix == "hin" and word[-4] == "i") or 

                        (suffix == "hon" and word[-4] == "o") or 

                        (suffix == "h\xE4n" and word[-4] == "\xE4") or 

                        (suffix == "h\xF6n" and word[-4] == "\xF6")): 

                        word = word[:-3] 

                        r1 = r1[:-3] 

                        r2 = r2[:-3] 

                        step3_success = True 

 

                elif suffix in ("siin", "den", "tten"): 

                    if (word[-len(suffix)-1] == "i" and 

                        word[-len(suffix)-2] in self.__restricted_vowels): 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        step3_success = True 

                    else: 

                        continue 

 

                elif suffix == "seen": 

                    if word[-6:-4] in self.__long_vowels: 

                        word = word[:-4] 

                        r1 = r1[:-4] 

                        r2 = r2[:-4] 

                        step3_success = True 

                    else: 

                        continue 

 

                elif suffix in ("a", "\xE4"): 

                    if word[-2] in self.__vowels and word[-3] in self.__consonants: 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                        r2 = r2[:-1] 

                        step3_success = True 

 

                elif suffix in ("tta", "tt\xE4"): 

                    if word[-4] == "e": 

                        word = word[:-3] 

                        r1 = r1[:-3] 

                        r2 = r2[:-3] 

                        step3_success = True 

 

                elif suffix == "n": 

                    word = word[:-1] 

                    r1 = r1[:-1] 

                    r2 = r2[:-1] 

                    step3_success = True 

 

                    if word[-2:] == "ie" or word[-2:] in self.__long_vowels: 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                        r2 = r2[:-1] 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                    step3_success = True 

                break 

 

        # STEP 4: Other endings 

        for suffix in self.__step4_suffixes: 

            if r2.endswith(suffix): 

                if suffix in ("mpi", "mpa", "mp\xE4", "mmi", "mma", 

                              "mm\xE4"): 

                    if word[-5:-3] != "po": 

                        word = word[:-3] 

                        r1 = r1[:-3] 

                        r2 = r2[:-3] 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                break 

 

        # STEP 5: Plurals 

        if step3_success and len(r1) >= 1 and r1[-1] in "ij": 

            word = word[:-1] 

            r1 = r1[:-1] 

 

        elif (not step3_success and len(r1) >= 2 and 

              r1[-1] == "t" and r1[-2] in self.__vowels): 

            word = word[:-1] 

            r1 = r1[:-1] 

            r2 = r2[:-1] 

            if r2.endswith("imma"): 

                word = word[:-4] 

                r1 = r1[:-4] 

            elif r2.endswith("mma") and r2[-5:-3] != "po": 

                word = word[:-3] 

                r1 = r1[:-3] 

 

        # STEP 6: Tidying up 

        if r1[-2:] in self.__long_vowels: 

            word = word[:-1] 

            r1 = r1[:-1] 

 

        if (len(r1) >= 2 and r1[-2] in self.__consonants and 

            r1[-1] in "a\xE4ei"): 

            word = word[:-1] 

            r1 = r1[:-1] 

 

        if r1.endswith(("oj", "uj")): 

            word = word[:-1] 

            r1 = r1[:-1] 

 

        if r1.endswith("jo"): 

            word = word[:-1] 

            r1 = r1[:-1] 

 

        # If the word ends with a double consonant 

        # followed by zero or more vowels, the last consonant is removed. 

        for i in range(1, len(word)): 

            if word[-i] in self.__vowels: 

                continue 

            else: 

                if i == 1: 

                    if word[-i-1:] in self.__double_consonants: 

                        word = word[:-1] 

                else: 

                    if word[-i-1:-i+1] in self.__double_consonants: 

                        word = "".join((word[:-i], word[-i+1:])) 

                break 

 

 

        return word 

 

 

 

class FrenchStemmer(_StandardStemmer): 

 

    """ 

    The French Snowball stemmer. 

 

    :cvar __vowels: The French vowels. 

    :type __vowels: unicode 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2a_suffixes: Suffixes to be deleted in step 2a of the algorithm. 

    :type __step2a_suffixes: tuple 

    :cvar __step2b_suffixes: Suffixes to be deleted in step 2b of the algorithm. 

    :type __step2b_suffixes: tuple 

    :cvar __step4_suffixes: Suffixes to be deleted in step 4 of the algorithm. 

    :type __step4_suffixes: tuple 

    :note: A detailed description of the French 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/french/stemmer.html 

    """ 

 

    __vowels = "aeiouy\xE2\xE0\xEB\xE9\xEA\xE8\xEF\xEE\xF4\xFB\xF9" 

    __step1_suffixes = ('issements', 'issement', 'atrices', 'atrice', 

                        'ateurs', 'ations', 'logies', 'usions', 

                        'utions', 'ements', 'amment', 'emment', 

                        'ances', 'iqUes', 'ismes', 'ables', 'istes', 

                        'ateur', 'ation', 'logie', 'usion', 'ution', 

                        'ences', 'ement', 'euses', 'ments', 'ance', 

                        'iqUe', 'isme', 'able', 'iste', 'ence', 

                        'it\xE9s', 'ives', 'eaux', 'euse', 'ment', 

                        'eux', 'it\xE9', 'ive', 'ifs', 'aux', 'if') 

    __step2a_suffixes = ('issaIent', 'issantes', 'iraIent', 'issante', 

                         'issants', 'issions', 'irions', 'issais', 

                         'issait', 'issant', 'issent', 'issiez', 'issons', 

                         'irais', 'irait', 'irent', 'iriez', 'irons', 

                         'iront', 'isses', 'issez', '\xEEmes', 

                         '\xEEtes', 'irai', 'iras', 'irez', 'isse', 

                         'ies', 'ira', '\xEEt', 'ie', 'ir', 'is', 

                         'it', 'i') 

    __step2b_suffixes = ('eraIent', 'assions', 'erions', 'assent', 

                         'assiez', '\xE8rent', 'erais', 'erait', 

                         'eriez', 'erons', 'eront', 'aIent', 'antes', 

                         'asses', 'ions', 'erai', 'eras', 'erez', 

                         '\xE2mes', '\xE2tes', 'ante', 'ants', 

                         'asse', '\xE9es', 'era', 'iez', 'ais', 

                         'ait', 'ant', '\xE9e', '\xE9s', 'er', 

                         'ez', '\xE2t', 'ai', 'as', '\xE9', 'a') 

    __step4_suffixes = ('i\xE8re', 'I\xE8re', 'ion', 'ier', 'Ier', 

                        'e', '\xEB') 

 

    def stem(self, word): 

        """ 

        Stem a French word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        step1_success = False 

        rv_ending_found = False 

        step2a_success = False 

        step2b_success = False 

 

        # Every occurrence of 'u' after 'q' is put into upper case. 

        for i in range(1, len(word)): 

            if word[i-1] == "q" and word[i] == "u": 

                word = "".join((word[:i], "U", word[i+1:])) 

 

        # Every occurrence of 'u' and 'i' 

        # between vowels is put into upper case. 

        # Every occurrence of 'y' preceded or 

        # followed by a vowel is also put into upper case. 

        for i in range(1, len(word)-1): 

            if word[i-1] in self.__vowels and word[i+1] in self.__vowels: 

                if word[i] == "u": 

                    word = "".join((word[:i], "U", word[i+1:])) 

 

                elif word[i] == "i": 

                    word = "".join((word[:i], "I", word[i+1:])) 

 

            if word[i-1] in self.__vowels or word[i+1] in self.__vowels: 

                if word[i] == "y": 

                    word = "".join((word[:i], "Y", word[i+1:])) 

 

        r1, r2 = self._r1r2_standard(word, self.__vowels) 

        rv = self.__rv_french(word, self.__vowels) 

 

        # STEP 1: Standard suffix removal 

        for suffix in self.__step1_suffixes: 

            if word.endswith(suffix): 

                if suffix == "eaux": 

                    word = word[:-1] 

                    step1_success = True 

 

                elif suffix in ("euse", "euses"): 

                    if suffix in r2: 

                        word = word[:-len(suffix)] 

                        step1_success = True 

 

                    elif suffix in r1: 

                        word = "".join((word[:-len(suffix)], "eux")) 

                        step1_success = True 

 

                elif suffix in ("ement", "ements") and suffix in rv: 

                    word = word[:-len(suffix)] 

                    step1_success = True 

 

                    if word[-2:] == "iv" and "iv" in r2: 

                        word = word[:-2] 

 

                        if word[-2:] == "at" and "at" in r2: 

                            word = word[:-2] 

 

                    elif word[-3:] == "eus": 

                        if "eus" in r2: 

                            word = word[:-3] 

                        elif "eus" in r1: 

                            word = "".join((word[:-1], "x")) 

 

                    elif word[-3:] in ("abl", "iqU"): 

                        if "abl" in r2 or "iqU" in r2: 

                            word = word[:-3] 

 

                    elif word[-3:] in ("i\xE8r", "I\xE8r"): 

                        if "i\xE8r" in rv or "I\xE8r" in rv: 

                            word = "".join((word[:-3], "i")) 

 

                elif suffix == "amment" and suffix in rv: 

                    word = "".join((word[:-6], "ant")) 

                    rv = "".join((rv[:-6], "ant")) 

                    rv_ending_found = True 

 

                elif suffix == "emment" and suffix in rv: 

                    word = "".join((word[:-6], "ent")) 

                    rv_ending_found = True 

 

                elif (suffix in ("ment", "ments") and suffix in rv and 

                      not rv.startswith(suffix) and 

                      rv[rv.rindex(suffix)-1] in self.__vowels): 

                    word = word[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

                    rv_ending_found = True 

 

                elif suffix == "aux" and suffix in r1: 

                    word = "".join((word[:-2], "l")) 

                    step1_success = True 

 

                elif (suffix in ("issement", "issements") and suffix in r1 

                      and word[-len(suffix)-1] not in self.__vowels): 

                    word = word[:-len(suffix)] 

                    step1_success = True 

 

                elif suffix in ("ance", "iqUe", "isme", "able", "iste", 

                              "eux", "ances", "iqUes", "ismes", 

                              "ables", "istes") and suffix in r2: 

                    word = word[:-len(suffix)] 

                    step1_success = True 

 

                elif suffix in ("atrice", "ateur", "ation", "atrices", 

                                "ateurs", "ations") and suffix in r2: 

                    word = word[:-len(suffix)] 

                    step1_success = True 

 

                    if word[-2:] == "ic": 

                        if "ic" in r2: 

                            word = word[:-2] 

                        else: 

                            word = "".join((word[:-2], "iqU")) 

 

                elif suffix in ("logie", "logies") and suffix in r2: 

                    word = "".join((word[:-len(suffix)], "log")) 

                    step1_success = True 

 

                elif (suffix in ("usion", "ution", "usions", "utions") and 

                      suffix in r2): 

                    word = "".join((word[:-len(suffix)], "u")) 

                    step1_success = True 

 

                elif suffix in ("ence", "ences") and suffix in r2: 

                    word = "".join((word[:-len(suffix)], "ent")) 

                    step1_success = True 

 

                elif suffix in ("it\xE9", "it\xE9s") and suffix in r2: 

                    word = word[:-len(suffix)] 

                    step1_success = True 

 

                    if word[-4:] == "abil": 

                        if "abil" in r2: 

                            word = word[:-4] 

                        else: 

                            word = "".join((word[:-2], "l")) 

 

                    elif word[-2:] == "ic": 

                        if "ic" in r2: 

                            word = word[:-2] 

                        else: 

                            word = "".join((word[:-2], "iqU")) 

 

                    elif word[-2:] == "iv": 

                        if "iv" in r2: 

                            word = word[:-2] 

 

                elif (suffix in ("if", "ive", "ifs", "ives") and 

                      suffix in r2): 

                    word = word[:-len(suffix)] 

                    step1_success = True 

 

                    if word[-2:] == "at" and "at" in r2: 

                        word = word[:-2] 

 

                        if word[-2:] == "ic": 

                            if "ic" in r2: 

                                word = word[:-2] 

                            else: 

                                word = "".join((word[:-2], "iqU")) 

                break 

 

        # STEP 2a: Verb suffixes beginning 'i' 

        if not step1_success or rv_ending_found: 

            for suffix in self.__step2a_suffixes: 

                if word.endswith(suffix): 

                    if (suffix in rv and len(rv) > len(suffix) and 

                        rv[rv.rindex(suffix)-1] not in self.__vowels): 

                        word = word[:-len(suffix)] 

                        step2a_success = True 

                    break 

 

        # STEP 2b: Other verb suffixes 

            if not step2a_success: 

                for suffix in self.__step2b_suffixes: 

                    if rv.endswith(suffix): 

                        if suffix == "ions" and "ions" in r2: 

                            word = word[:-4] 

                            step2b_success = True 

 

                        elif suffix in ('eraIent', 'erions', '\xE8rent', 

                                        'erais', 'erait', 'eriez', 

                                        'erons', 'eront', 'erai', 'eras', 

                                        'erez', '\xE9es', 'era', 'iez', 

                                        '\xE9e', '\xE9s', 'er', 'ez', 

                                        '\xE9'): 

                            word = word[:-len(suffix)] 

                            step2b_success = True 

 

                        elif suffix in ('assions', 'assent', 'assiez', 

                                        'aIent', 'antes', 'asses', 

                                        '\xE2mes', '\xE2tes', 'ante', 

                                        'ants', 'asse', 'ais', 'ait', 

                                        'ant', '\xE2t', 'ai', 'as', 

                                        'a'): 

                            word = word[:-len(suffix)] 

                            rv = rv[:-len(suffix)] 

                            step2b_success = True 

                            if rv.endswith("e"): 

                                word = word[:-1] 

                        break 

 

        # STEP 3 

        if step1_success or step2a_success or step2b_success: 

            if word[-1] == "Y": 

                word = "".join((word[:-1], "i")) 

            elif word[-1] == "\xE7": 

                word = "".join((word[:-1], "c")) 

 

        # STEP 4: Residual suffixes 

        else: 

            if (len(word) >= 2 and word[-1] == "s" and 

                word[-2] not in "aiou\xE8s"): 

                word = word[:-1] 

 

            for suffix in self.__step4_suffixes: 

                if word.endswith(suffix): 

                    if suffix in rv: 

                        if (suffix == "ion" and suffix in r2 and 

                            rv[-4] in "st"): 

                            word = word[:-3] 

 

                        elif suffix in ("ier", "i\xE8re", "Ier", 

                                        "I\xE8re"): 

                            word = "".join((word[:-len(suffix)], "i")) 

 

                        elif suffix == "e": 

                            word = word[:-1] 

 

                        elif suffix == "\xEB" and word[-3:-1] == "gu": 

                            word = word[:-1] 

                        break 

 

        # STEP 5: Undouble 

        if word.endswith(("enn", "onn", "ett", "ell", "eill")): 

            word = word[:-1] 

 

        # STEP 6: Un-accent 

        for i in range(1, len(word)): 

            if word[-i] not in self.__vowels: 

                i += 1 

            else: 

                if i != 1 and word[-i] in ("\xE9", "\xE8"): 

                    word = "".join((word[:-i], "e", word[-i+1:])) 

                break 

 

        word = (word.replace("I", "i") 

                    .replace("U", "u") 

                    .replace("Y", "y")) 

 

 

        return word 

 

 

 

    def __rv_french(self, word, vowels): 

        """ 

        Return the region RV that is used by the French stemmer. 

 

        If the word begins with two vowels, RV is the region after 

        the third letter. Otherwise, it is the region after the first 

        vowel not at the beginning of the word, or the end of the word 

        if these positions cannot be found. (Exceptionally, u'par', 

        u'col' or u'tap' at the beginning of a word is also taken to 

        define RV as the region to their right.) 

 

        :param word: The French word whose region RV is determined. 

        :type word: str or unicode 

        :param vowels: The French vowels that are used to determine 

                       the region RV. 

        :type vowels: unicode 

        :return: the region RV for the respective French word. 

        :rtype: unicode 

        :note: This helper method is invoked by the stem method of 

               the subclass FrenchStemmer. It is not to be invoked directly! 

 

        """ 

        rv = "" 

        if len(word) >= 2: 

            if (word.startswith(("par", "col", "tap")) or 

                (word[0] in vowels and word[1] in vowels)): 

                rv = word[3:] 

            else: 

                for i in range(1, len(word)): 

                    if word[i] in vowels: 

                        rv = word[i+1:] 

                        break 

 

        return rv 

 

 

 

class GermanStemmer(_StandardStemmer): 

 

    """ 

    The German Snowball stemmer. 

 

    :cvar __vowels: The German vowels. 

    :type __vowels: unicode 

    :cvar __s_ending: Letters that may directly appear before a word final 's'. 

    :type __s_ending: unicode 

    :cvar __st_ending: Letter that may directly appear before a word final 'st'. 

    :type __st_ending: unicode 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :note: A detailed description of the German 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/german/stemmer.html 

 

    """ 

 

    __vowels = "aeiouy\xE4\xF6\xFC" 

    __s_ending = "bdfghklmnrt" 

    __st_ending = "bdfghklmnt" 

 

    __step1_suffixes = ("ern", "em", "er", "en", "es", "e", "s") 

    __step2_suffixes = ("est", "en", "er", "st") 

    __step3_suffixes = ("isch", "lich", "heit", "keit", 

                          "end", "ung", "ig", "ik") 

 

    def stem(self, word): 

        """ 

        Stem a German word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        word = word.replace("\xDF", "ss") 

 

        # Every occurrence of 'u' and 'y' 

        # between vowels is put into upper case. 

        for i in range(1, len(word)-1): 

            if word[i-1] in self.__vowels and word[i+1] in self.__vowels: 

                if word[i] == "u": 

                    word = "".join((word[:i], "U", word[i+1:])) 

 

                elif word[i] == "y": 

                    word = "".join((word[:i], "Y", word[i+1:])) 

 

        r1, r2 = self._r1r2_standard(word, self.__vowels) 

 

        # R1 is adjusted so that the region before it 

        # contains at least 3 letters. 

        for i in range(1, len(word)): 

            if word[i] not in self.__vowels and word[i-1] in self.__vowels: 

                if len(word[:i+1]) < 3 and len(word[:i+1]) > 0: 

                    r1 = word[3:] 

                elif len(word[:i+1]) == 0: 

                    return word 

                break 

 

        # STEP 1 

        for suffix in self.__step1_suffixes: 

            if r1.endswith(suffix): 

                if (suffix in ("en", "es", "e") and 

                    word[-len(suffix)-4:-len(suffix)] == "niss"): 

                    word = word[:-len(suffix)-1] 

                    r1 = r1[:-len(suffix)-1] 

                    r2 = r2[:-len(suffix)-1] 

 

                elif suffix == "s": 

                    if word[-2] in self.__s_ending: 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                        r2 = r2[:-1] 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                break 

 

        # STEP 2 

        for suffix in self.__step2_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "st": 

                    if word[-3] in self.__st_ending and len(word[:-3]) >= 3: 

                        word = word[:-2] 

                        r1 = r1[:-2] 

                        r2 = r2[:-2] 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                break 

 

        # STEP 3: Derivational suffixes 

        for suffix in self.__step3_suffixes: 

            if r2.endswith(suffix): 

                if suffix in ("end", "ung"): 

                    if ("ig" in r2[-len(suffix)-2:-len(suffix)] and 

                        "e" not in r2[-len(suffix)-3:-len(suffix)-2]): 

                        word = word[:-len(suffix)-2] 

                    else: 

                        word = word[:-len(suffix)] 

 

                elif (suffix in ("ig", "ik", "isch") and 

                      "e" not in r2[-len(suffix)-1:-len(suffix)]): 

                    word = word[:-len(suffix)] 

 

                elif suffix in ("lich", "heit"): 

                    if ("er" in r1[-len(suffix)-2:-len(suffix)] or 

                        "en" in r1[-len(suffix)-2:-len(suffix)]): 

                        word = word[:-len(suffix)-2] 

                    else: 

                        word = word[:-len(suffix)] 

 

                elif suffix == "keit": 

                    if "lich" in r2[-len(suffix)-4:-len(suffix)]: 

                        word = word[:-len(suffix)-4] 

 

                    elif "ig" in r2[-len(suffix)-2:-len(suffix)]: 

                        word = word[:-len(suffix)-2] 

                    else: 

                        word = word[:-len(suffix)] 

                break 

 

        # Umlaut accents are removed and 

        # 'u' and 'y' are put back into lower case. 

        word = (word.replace("\xE4", "a").replace("\xF6", "o") 

                    .replace("\xFC", "u").replace("U", "u") 

                    .replace("Y", "y")) 

 

 

        return word 

 

 

 

class HungarianStemmer(_LanguageSpecificStemmer): 

 

    """ 

    The Hungarian Snowball stemmer. 

 

    :cvar __vowels: The Hungarian vowels. 

    :type __vowels: unicode 

    :cvar __digraphs: The Hungarian digraphs. 

    :type __digraphs: tuple 

    :cvar __double_consonants: The Hungarian double consonants. 

    :type __double_consonants: tuple 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :cvar __step4_suffixes: Suffixes to be deleted in step 4 of the algorithm. 

    :type __step4_suffixes: tuple 

    :cvar __step5_suffixes: Suffixes to be deleted in step 5 of the algorithm. 

    :type __step5_suffixes: tuple 

    :cvar __step6_suffixes: Suffixes to be deleted in step 6 of the algorithm. 

    :type __step6_suffixes: tuple 

    :cvar __step7_suffixes: Suffixes to be deleted in step 7 of the algorithm. 

    :type __step7_suffixes: tuple 

    :cvar __step8_suffixes: Suffixes to be deleted in step 8 of the algorithm. 

    :type __step8_suffixes: tuple 

    :cvar __step9_suffixes: Suffixes to be deleted in step 9 of the algorithm. 

    :type __step9_suffixes: tuple 

    :note: A detailed description of the Hungarian 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/hungarian/stemmer.html 

 

    """ 

 

    __vowels = "aeiou\xF6\xFC\xE1\xE9\xED\xF3\xF5\xFA\xFB" 

    __digraphs = ("cs", "dz", "dzs", "gy", "ly", "ny", "ty", "zs") 

    __double_consonants = ("bb", "cc", "ccs", "dd", "ff", "gg", 

                             "ggy", "jj", "kk", "ll", "lly", "mm", 

                             "nn", "nny", "pp", "rr", "ss", "ssz", 

                             "tt", "tty", "vv", "zz", "zzs") 

 

    __step1_suffixes = ("al", "el") 

    __step2_suffixes = ('k\xE9ppen', 'onk\xE9nt', 'enk\xE9nt', 

                        'ank\xE9nt', 'k\xE9pp', 'k\xE9nt', 'ban', 

                        'ben', 'nak', 'nek', 'val', 'vel', 't\xF3l', 

                        't\xF5l', 'r\xF3l', 'r\xF5l', 'b\xF3l', 

                        'b\xF5l', 'hoz', 'hez', 'h\xF6z', 

                        'n\xE1l', 'n\xE9l', '\xE9rt', 'kor', 

                        'ba', 'be', 'ra', 're', 'ig', 'at', 'et', 

                        'ot', '\xF6t', 'ul', '\xFCl', 'v\xE1', 

                        'v\xE9', 'en', 'on', 'an', '\xF6n', 

                        'n', 't') 

    __step3_suffixes = ("\xE1nk\xE9nt", "\xE1n", "\xE9n") 

    __step4_suffixes = ('astul', 'est\xFCl', '\xE1stul', 

                        '\xE9st\xFCl', 'stul', 'st\xFCl') 

    __step5_suffixes = ("\xE1", "\xE9") 

    __step6_suffixes = ('ok\xE9', '\xF6k\xE9', 'ak\xE9', 

                        'ek\xE9', '\xE1k\xE9', '\xE1\xE9i', 

                        '\xE9k\xE9', '\xE9\xE9i', 'k\xE9', 

                        '\xE9i', '\xE9\xE9', '\xE9') 

    __step7_suffixes = ('\xE1juk', '\xE9j\xFCk', '\xFCnk', 

                        'unk', 'juk', 'j\xFCk', '\xE1nk', 

                        '\xE9nk', 'nk', 'uk', '\xFCk', 'em', 

                        'om', 'am', 'od', 'ed', 'ad', '\xF6d', 

                        'ja', 'je', '\xE1m', '\xE1d', '\xE9m', 

                        '\xE9d', 'm', 'd', 'a', 'e', 'o', 

                        '\xE1', '\xE9') 

    __step8_suffixes = ('jaitok', 'jeitek', 'jaink', 'jeink', 'aitok', 

                        'eitek', '\xE1itok', '\xE9itek', 'jaim', 

                        'jeim', 'jaid', 'jeid', 'eink', 'aink', 

                        'itek', 'jeik', 'jaik', '\xE1ink', 

                        '\xE9ink', 'aim', 'eim', 'aid', 'eid', 

                        'jai', 'jei', 'ink', 'aik', 'eik', 

                        '\xE1im', '\xE1id', '\xE1ik', '\xE9im', 

                        '\xE9id', '\xE9ik', 'im', 'id', 'ai', 

                        'ei', 'ik', '\xE1i', '\xE9i', 'i') 

    __step9_suffixes = ("\xE1k", "\xE9k", "\xF6k", "ok", 

                        "ek", "ak", "k") 

 

    def stem(self, word): 

        """ 

        Stem an Hungarian word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        r1 = self.__r1_hungarian(word, self.__vowels, self.__digraphs) 

 

        # STEP 1: Remove instrumental case 

        if r1.endswith(self.__step1_suffixes): 

            for double_cons in self.__double_consonants: 

                if word[-2-len(double_cons):-2] == double_cons: 

                    word = "".join((word[:-4], word[-3])) 

 

                    if r1[-2-len(double_cons):-2] == double_cons: 

                        r1 = "".join((r1[:-4], r1[-3])) 

                    break 

 

        # STEP 2: Remove frequent cases 

        for suffix in self.__step2_suffixes: 

            if word.endswith(suffix): 

                if r1.endswith(suffix): 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

 

                    if r1.endswith("\xE1"): 

                        word = "".join((word[:-1], "a")) 

                        r1 = "".join((r1[:-1], "a")) 

 

                    elif r1.endswith("\xE9"): 

                        word = "".join((word[:-1], "e")) 

                        r1 = "".join((r1[:-1], "e")) 

                break 

 

        # STEP 3: Remove special cases 

        for suffix in self.__step3_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "\xE9n": 

                    word = "".join((word[:-2], "e")) 

                    r1 = "".join((r1[:-2], "e")) 

                else: 

                    word = "".join((word[:-len(suffix)], "a")) 

                    r1 = "".join((r1[:-len(suffix)], "a")) 

                break 

 

        # STEP 4: Remove other cases 

        for suffix in self.__step4_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "\xE1stul": 

                    word = "".join((word[:-5], "a")) 

                    r1 = "".join((r1[:-5], "a")) 

 

                elif suffix == "\xE9st\xFCl": 

                    word = "".join((word[:-5], "e")) 

                    r1 = "".join((r1[:-5], "e")) 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                break 

 

        # STEP 5: Remove factive case 

        for suffix in self.__step5_suffixes: 

            if r1.endswith(suffix): 

                for double_cons in self.__double_consonants: 

                    if word[-1-len(double_cons):-1] == double_cons: 

                        word = "".join((word[:-3], word[-2])) 

 

                        if r1[-1-len(double_cons):-1] == double_cons: 

                            r1 = "".join((r1[:-3], r1[-2])) 

                        break 

 

        # STEP 6: Remove owned 

        for suffix in self.__step6_suffixes: 

            if r1.endswith(suffix): 

                if suffix in ("\xE1k\xE9", "\xE1\xE9i"): 

                    word = "".join((word[:-3], "a")) 

                    r1 = "".join((r1[:-3], "a")) 

 

                elif suffix in ("\xE9k\xE9", "\xE9\xE9i", 

                                "\xE9\xE9"): 

                    word = "".join((word[:-len(suffix)], "e")) 

                    r1 = "".join((r1[:-len(suffix)], "e")) 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                break 

 

        # STEP 7: Remove singular owner suffixes 

        for suffix in self.__step7_suffixes: 

            if word.endswith(suffix): 

                if r1.endswith(suffix): 

                    if suffix in ("\xE1nk", "\xE1juk", "\xE1m", 

                                  "\xE1d", "\xE1"): 

                        word = "".join((word[:-len(suffix)], "a")) 

                        r1 = "".join((r1[:-len(suffix)], "a")) 

 

                    elif suffix in ("\xE9nk", "\xE9j\xFCk", 

                                    "\xE9m", "\xE9d", "\xE9"): 

                        word = "".join((word[:-len(suffix)], "e")) 

                        r1 = "".join((r1[:-len(suffix)], "e")) 

                    else: 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                break 

 

        # STEP 8: Remove plural owner suffixes 

        for suffix in self.__step8_suffixes: 

            if word.endswith(suffix): 

                if r1.endswith(suffix): 

                    if suffix in ("\xE1im", "\xE1id", "\xE1i", 

                                  "\xE1ink", "\xE1itok", "\xE1ik"): 

                        word = "".join((word[:-len(suffix)], "a")) 

                        r1 = "".join((r1[:-len(suffix)], "a")) 

 

                    elif suffix in ("\xE9im", "\xE9id", "\xE9i", 

                                    "\xE9ink", "\xE9itek", "\xE9ik"): 

                        word = "".join((word[:-len(suffix)], "e")) 

                        r1 = "".join((r1[:-len(suffix)], "e")) 

                    else: 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                break 

 

        # STEP 9: Remove plural suffixes 

        for suffix in self.__step9_suffixes: 

            if word.endswith(suffix): 

                if r1.endswith(suffix): 

                    if suffix == "\xE1k": 

                        word = "".join((word[:-2], "a")) 

                    elif suffix == "\xE9k": 

                        word = "".join((word[:-2], "e")) 

                    else: 

                        word = word[:-len(suffix)] 

                break 

 

 

        return word 

 

 

 

    def __r1_hungarian(self, word, vowels, digraphs): 

        """ 

        Return the region R1 that is used by the Hungarian stemmer. 

 

        If the word begins with a vowel, R1 is defined as the region 

        after the first consonant or digraph (= two letters stand for 

        one phoneme) in the word. If the word begins with a consonant, 

        it is defined as the region after the first vowel in the word. 

        If the word does not contain both a vowel and consonant, R1 

        is the null region at the end of the word. 

 

        :param word: The Hungarian word whose region R1 is determined. 

        :type word: str or unicode 

        :param vowels: The Hungarian vowels that are used to determine 

                       the region R1. 

        :type vowels: unicode 

        :param digraphs: The digraphs that are used to determine the 

                         region R1. 

        :type digraphs: tuple 

        :return: the region R1 for the respective word. 

        :rtype: unicode 

        :note: This helper method is invoked by the stem method of the subclass 

               HungarianStemmer. It is not to be invoked directly! 

 

        """ 

        r1 = "" 

        if word[0] in vowels: 

            for digraph in digraphs: 

                if digraph in word[1:]: 

                    r1 = word[word.index(digraph[-1])+1:] 

                    return r1 

 

            for i in range(1, len(word)): 

                if word[i] not in vowels: 

                    r1 = word[i+1:] 

                    break 

        else: 

            for i in range(1, len(word)): 

                if word[i] in vowels: 

                    r1 = word[i+1:] 

                    break 

 

        return r1 

 

 

 

class ItalianStemmer(_StandardStemmer): 

 

    """ 

    The Italian Snowball stemmer. 

 

    :cvar __vowels: The Italian vowels. 

    :type __vowels: unicode 

    :cvar __step0_suffixes: Suffixes to be deleted in step 0 of the algorithm. 

    :type __step0_suffixes: tuple 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :note: A detailed description of the Italian 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/italian/stemmer.html 

 

    """ 

 

    __vowels = "aeiou\xE0\xE8\xEC\xF2\xF9" 

    __step0_suffixes = ('gliela', 'gliele', 'glieli', 'glielo', 

                        'gliene', 'sene', 'mela', 'mele', 'meli', 

                        'melo', 'mene', 'tela', 'tele', 'teli', 

                        'telo', 'tene', 'cela', 'cele', 'celi', 

                        'celo', 'cene', 'vela', 'vele', 'veli', 

                        'velo', 'vene', 'gli', 'ci', 'la', 'le', 

                        'li', 'lo', 'mi', 'ne', 'si', 'ti', 'vi') 

    __step1_suffixes = ('atrice', 'atrici', 'azione', 'azioni', 

                        'uzione', 'uzioni', 'usione', 'usioni', 

                        'amento', 'amenti', 'imento', 'imenti', 

                        'amente', 'abile', 'abili', 'ibile', 'ibili', 

                        'mente', 'atore', 'atori', 'logia', 'logie', 

                        'anza', 'anze', 'iche', 'ichi', 'ismo', 

                        'ismi', 'ista', 'iste', 'isti', 'ist\xE0', 

                        'ist\xE8', 'ist\xEC', 'ante', 'anti', 

                        'enza', 'enze', 'ico', 'ici', 'ica', 'ice', 

                        'oso', 'osi', 'osa', 'ose', 'it\xE0', 

                        'ivo', 'ivi', 'iva', 'ive') 

    __step2_suffixes = ('erebbero', 'irebbero', 'assero', 'assimo', 

                        'eranno', 'erebbe', 'eremmo', 'ereste', 

                        'eresti', 'essero', 'iranno', 'irebbe', 

                        'iremmo', 'ireste', 'iresti', 'iscano', 

                        'iscono', 'issero', 'arono', 'avamo', 'avano', 

                        'avate', 'eremo', 'erete', 'erono', 'evamo', 

                        'evano', 'evate', 'iremo', 'irete', 'irono', 

                        'ivamo', 'ivano', 'ivate', 'ammo', 'ando', 

                        'asse', 'assi', 'emmo', 'enda', 'ende', 

                        'endi', 'endo', 'erai', 'erei', 'Yamo', 

                        'iamo', 'immo', 'irai', 'irei', 'isca', 

                        'isce', 'isci', 'isco', 'ano', 'are', 'ata', 

                        'ate', 'ati', 'ato', 'ava', 'avi', 'avo', 

                        'er\xE0', 'ere', 'er\xF2', 'ete', 'eva', 

                        'evi', 'evo', 'ir\xE0', 'ire', 'ir\xF2', 

                        'ita', 'ite', 'iti', 'ito', 'iva', 'ivi', 

                        'ivo', 'ono', 'uta', 'ute', 'uti', 'uto', 

                        'ar', 'ir') 

 

    def stem(self, word): 

        """ 

        Stem an Italian word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        step1_success = False 

 

        # All acute accents are replaced by grave accents. 

        word = (word.replace("\xE1", "\xE0") 

                    .replace("\xE9", "\xE8") 

                    .replace("\xED", "\xEC") 

                    .replace("\xF3", "\xF2") 

                    .replace("\xFA", "\xF9")) 

 

        # Every occurrence of 'u' after 'q' 

        # is put into upper case. 

        for i in range(1, len(word)): 

            if word[i-1] == "q" and word[i] == "u": 

                word = "".join((word[:i], "U", word[i+1:])) 

 

        # Every occurrence of 'u' and 'i' 

        # between vowels is put into upper case. 

        for i in range(1, len(word)-1): 

            if word[i-1] in self.__vowels and word[i+1] in self.__vowels: 

                if word[i] == "u": 

                    word = "".join((word[:i], "U", word[i+1:])) 

 

                elif word [i] == "i": 

                    word = "".join((word[:i], "I", word[i+1:])) 

 

        r1, r2 = self._r1r2_standard(word, self.__vowels) 

        rv = self._rv_standard(word, self.__vowels) 

 

        # STEP 0: Attached pronoun 

        for suffix in self.__step0_suffixes: 

            if rv.endswith(suffix): 

                if rv[-len(suffix)-4:-len(suffix)] in ("ando", "endo"): 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

 

                elif (rv[-len(suffix)-2:-len(suffix)] in 

                      ("ar", "er", "ir")): 

                    word = "".join((word[:-len(suffix)], "e")) 

                    r1 = "".join((r1[:-len(suffix)], "e")) 

                    r2 = "".join((r2[:-len(suffix)], "e")) 

                    rv = "".join((rv[:-len(suffix)], "e")) 

                break 

 

        # STEP 1: Standard suffix removal 

        for suffix in self.__step1_suffixes: 

            if word.endswith(suffix): 

                if suffix == "amente" and r1.endswith(suffix): 

                    step1_success = True 

                    word = word[:-6] 

                    r2 = r2[:-6] 

                    rv = rv[:-6] 

 

                    if r2.endswith("iv"): 

                        word = word[:-2] 

                        r2 = r2[:-2] 

                        rv = rv[:-2] 

 

                        if r2.endswith("at"): 

                            word = word[:-2] 

                            rv = rv[:-2] 

 

                    elif r2.endswith(("os", "ic")): 

                        word = word[:-2] 

                        rv = rv[:-2] 

 

                    elif r2 .endswith("abil"): 

                        word = word[:-4] 

                        rv = rv[:-4] 

 

                elif (suffix in ("amento", "amenti", 

                                 "imento", "imenti") and 

                      rv.endswith(suffix)): 

                    step1_success = True 

                    word = word[:-6] 

                    rv = rv[:-6] 

 

                elif r2.endswith(suffix): 

                    step1_success = True 

                    if suffix in ("azione", "azioni", "atore", "atori"): 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

 

                        if r2.endswith("ic"): 

                            word = word[:-2] 

                            rv = rv[:-2] 

 

                    elif suffix in ("logia", "logie"): 

                        word = word[:-2] 

                        rv = word[:-2] 

 

                    elif suffix in ("uzione", "uzioni", 

                                    "usione", "usioni"): 

                        word = word[:-5] 

                        rv = rv[:-5] 

 

                    elif suffix in ("enza", "enze"): 

                        word = "".join((word[:-2], "te")) 

                        rv = "".join((rv[:-2], "te")) 

 

                    elif suffix == "it\xE0": 

                        word = word[:-3] 

                        r2 = r2[:-3] 

                        rv = rv[:-3] 

 

                        if r2.endswith(("ic", "iv")): 

                            word = word[:-2] 

                            rv = rv[:-2] 

 

                        elif r2.endswith("abil"): 

                            word = word[:-4] 

                            rv = rv[:-4] 

 

                    elif suffix in ("ivo", "ivi", "iva", "ive"): 

                        word = word[:-3] 

                        r2 = r2[:-3] 

                        rv = rv[:-3] 

 

                        if r2.endswith("at"): 

                            word = word[:-2] 

                            r2 = r2[:-2] 

                            rv = rv[:-2] 

 

                            if r2.endswith("ic"): 

                                word = word[:-2] 

                                rv = rv[:-2] 

                    else: 

                        word = word[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                break 

 

        # STEP 2: Verb suffixes 

        if not step1_success: 

            for suffix in self.__step2_suffixes: 

                if rv.endswith(suffix): 

                    word = word[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

                    break 

 

        # STEP 3a 

        if rv.endswith(("a", "e", "i", "o", "\xE0", "\xE8", 

                        "\xEC", "\xF2")): 

            word = word[:-1] 

            rv = rv[:-1] 

 

            if rv.endswith("i"): 

                word = word[:-1] 

                rv = rv[:-1] 

 

        # STEP 3b 

        if rv.endswith(("ch", "gh")): 

            word = word[:-1] 

 

        word = word.replace("I", "i").replace("U", "u") 

 

 

        return word 

 

 

 

class NorwegianStemmer(_ScandinavianStemmer): 

 

    """ 

    The Norwegian Snowball stemmer. 

 

    :cvar __vowels: The Norwegian vowels. 

    :type __vowels: unicode 

    :cvar __s_ending: Letters that may directly appear before a word final 's'. 

    :type __s_ending: unicode 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :note: A detailed description of the Norwegian 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/norwegian/stemmer.html 

 

    """ 

 

    __vowels = "aeiouy\xE6\xE5\xF8" 

    __s_ending = "bcdfghjlmnoprtvyz" 

    __step1_suffixes = ("hetenes", "hetene", "hetens", "heter", 

                        "heten", "endes", "ande", "ende", "edes", 

                        "enes", "erte", "ede", "ane", "ene", "ens", 

                        "ers", "ets", "het", "ast", "ert", "en", 

                        "ar", "er", "as", "es", "et", "a", "e", "s") 

 

    __step2_suffixes = ("dt", "vt") 

 

    __step3_suffixes = ("hetslov", "eleg", "elig", "elov", "slov", 

                          "leg", "eig", "lig", "els", "lov", "ig") 

 

    def stem(self, word): 

        """ 

        Stem a Norwegian word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        r1 = self._r1_scandinavian(word, self.__vowels) 

 

        # STEP 1 

        for suffix in self.__step1_suffixes: 

            if r1.endswith(suffix): 

                if suffix in ("erte", "ert"): 

                    word = "".join((word[:-len(suffix)], "er")) 

                    r1 = "".join((r1[:-len(suffix)], "er")) 

 

                elif suffix == "s": 

                    if (word[-2] in self.__s_ending or 

                        (word[-2] == "k" and word[-3] not in self.__vowels)): 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                break 

 

        # STEP 2 

        for suffix in self.__step2_suffixes: 

            if r1.endswith(suffix): 

                word = word[:-1] 

                r1 = r1[:-1] 

                break 

 

        # STEP 3 

        for suffix in self.__step3_suffixes: 

            if r1.endswith(suffix): 

                word = word[:-len(suffix)] 

                break 

 

 

        return word 

 

 

 

class PortugueseStemmer(_StandardStemmer): 

 

    """ 

    The Portuguese Snowball stemmer. 

 

    :cvar __vowels: The Portuguese vowels. 

    :type __vowels: unicode 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step4_suffixes: Suffixes to be deleted in step 4 of the algorithm. 

    :type __step4_suffixes: tuple 

    :note: A detailed description of the Portuguese 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/portuguese/stemmer.html 

 

    """ 

 

    __vowels = "aeiou\xE1\xE9\xED\xF3\xFA\xE2\xEA\xF4" 

    __step1_suffixes = ('amentos', 'imentos', 'uciones', 'amento', 

                        'imento', 'adoras', 'adores', 'a\xE7o~es', 

                        'log\xEDas', '\xEAncias', 'amente', 

                        'idades', 'ismos', 'istas', 'adora', 

                        'a\xE7a~o', 'antes', '\xE2ncia', 

                        'log\xEDa', 'uci\xF3n', '\xEAncia', 

                        'mente', 'idade', 'ezas', 'icos', 'icas', 

                        'ismo', '\xE1vel', '\xEDvel', 'ista', 

                        'osos', 'osas', 'ador', 'ante', 'ivas', 

                        'ivos', 'iras', 'eza', 'ico', 'ica', 

                        'oso', 'osa', 'iva', 'ivo', 'ira') 

    __step2_suffixes = ('ar\xEDamos', 'er\xEDamos', 'ir\xEDamos', 

                        '\xE1ssemos', '\xEAssemos', '\xEDssemos', 

                        'ar\xEDeis', 'er\xEDeis', 'ir\xEDeis', 

                        '\xE1sseis', '\xE9sseis', '\xEDsseis', 

                        '\xE1ramos', '\xE9ramos', '\xEDramos', 

                        '\xE1vamos', 'aremos', 'eremos', 'iremos', 

                        'ariam', 'eriam', 'iriam', 'assem', 'essem', 

                        'issem', 'ara~o', 'era~o', 'ira~o', 'arias', 

                        'erias', 'irias', 'ardes', 'erdes', 'irdes', 

                        'asses', 'esses', 'isses', 'astes', 'estes', 

                        'istes', '\xE1reis', 'areis', '\xE9reis', 

                        'ereis', '\xEDreis', 'ireis', '\xE1veis', 

                        '\xEDamos', 'armos', 'ermos', 'irmos', 

                        'aria', 'eria', 'iria', 'asse', 'esse', 

                        'isse', 'aste', 'este', 'iste', 'arei', 

                        'erei', 'irei', 'aram', 'eram', 'iram', 

                        'avam', 'arem', 'erem', 'irem', 

                        'ando', 'endo', 'indo', 'adas', 'idas', 

                        'ar\xE1s', 'aras', 'er\xE1s', 'eras', 

                        'ir\xE1s', 'avas', 'ares', 'eres', 'ires', 

                        '\xEDeis', 'ados', 'idos', '\xE1mos', 

                        'amos', 'emos', 'imos', 'iras', 'ada', 'ida', 

                        'ar\xE1', 'ara', 'er\xE1', 'era', 

                        'ir\xE1', 'ava', 'iam', 'ado', 'ido', 

                        'ias', 'ais', 'eis', 'ira', 'ia', 'ei', 'am', 

                        'em', 'ar', 'er', 'ir', 'as', 

                        'es', 'is', 'eu', 'iu', 'ou') 

    __step4_suffixes = ("os", "a", "i", "o", "\xE1", 

                        "\xED", "\xF3") 

 

    def stem(self, word): 

        """ 

        Stem a Portuguese word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        step1_success = False 

        step2_success = False 

 

        word = (word.replace("\xE3", "a~") 

                    .replace("\xF5", "o~")) 

 

        r1, r2 = self._r1r2_standard(word, self.__vowels) 

        rv = self._rv_standard(word, self.__vowels) 

 

        # STEP 1: Standard suffix removal 

        for suffix in self.__step1_suffixes: 

            if word.endswith(suffix): 

                if suffix == "amente" and r1.endswith(suffix): 

                    step1_success = True 

 

                    word = word[:-6] 

                    r2 = r2[:-6] 

                    rv = rv[:-6] 

 

                    if r2.endswith("iv"): 

                        word = word[:-2] 

                        r2 = r2[:-2] 

                        rv = rv[:-2] 

 

                        if r2.endswith("at"): 

                            word = word[:-2] 

                            rv = rv[:-2] 

 

                    elif r2.endswith(("os", "ic", "ad")): 

                        word = word[:-2] 

                        rv = rv[:-2] 

 

                elif (suffix in ("ira", "iras") and rv.endswith(suffix) and 

                      word[-len(suffix)-1:-len(suffix)] == "e"): 

                    step1_success = True 

 

                    word = "".join((word[:-len(suffix)], "ir")) 

                    rv = "".join((rv[:-len(suffix)], "ir")) 

 

                elif r2.endswith(suffix): 

                    step1_success = True 

 

                    if suffix in ("log\xEDa", "log\xEDas"): 

                        word = word[:-2] 

                        rv = rv[:-2] 

 

                    elif suffix in ("uci\xF3n", "uciones"): 

                        word = "".join((word[:-len(suffix)], "u")) 

                        rv = "".join((rv[:-len(suffix)], "u")) 

 

                    elif suffix in ("\xEAncia", "\xEAncias"): 

                        word = "".join((word[:-len(suffix)], "ente")) 

                        rv = "".join((rv[:-len(suffix)], "ente")) 

 

                    elif suffix == "mente": 

                        word = word[:-5] 

                        r2 = r2[:-5] 

                        rv = rv[:-5] 

 

                        if r2.endswith(("ante", "avel", "\xEDvel")): 

                            word = word[:-4] 

                            rv = rv[:-4] 

 

                    elif suffix in ("idade", "idades"): 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

 

                        if r2.endswith(("ic", "iv")): 

                            word = word[:-2] 

                            rv = rv[:-2] 

 

                        elif r2.endswith("abil"): 

                            word = word[:-4] 

                            rv = rv[:-4] 

 

                    elif suffix in ("iva", "ivo", "ivas", "ivos"): 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

 

                        if r2.endswith("at"): 

                            word = word[:-2] 

                            rv = rv[:-2] 

                    else: 

                        word = word[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                break 

 

        # STEP 2: Verb suffixes 

        if not step1_success: 

            for suffix in self.__step2_suffixes: 

                if rv.endswith(suffix): 

                    step2_success = True 

 

                    word = word[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

                    break 

 

        # STEP 3 

        if step1_success or step2_success: 

            if rv.endswith("i") and word[-2] == "c": 

                word = word[:-1] 

                rv = rv[:-1] 

 

        ### STEP 4: Residual suffix 

        if not step1_success and not step2_success: 

            for suffix in self.__step4_suffixes: 

                if rv.endswith(suffix): 

                    word = word[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

                    break 

 

        # STEP 5 

        if rv.endswith(("e", "\xE9", "\xEA")): 

            word = word[:-1] 

            rv = rv[:-1] 

 

            if ((word.endswith("gu") and rv.endswith("u")) or 

                (word.endswith("ci") and rv.endswith("i"))): 

                word = word[:-1] 

 

        elif word.endswith("\xE7"): 

            word = "".join((word[:-1], "c")) 

 

        word = word.replace("a~", "\xE3").replace("o~", "\xF5") 

 

 

        return word 

 

 

 

class RomanianStemmer(_StandardStemmer): 

 

    """ 

    The Romanian Snowball stemmer. 

 

    :cvar __vowels: The Romanian vowels. 

    :type __vowels: unicode 

    :cvar __step0_suffixes: Suffixes to be deleted in step 0 of the algorithm. 

    :type __step0_suffixes: tuple 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :note: A detailed description of the Romanian 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/romanian/stemmer.html 

 

    """ 

 

    __vowels = "aeiou\u0103\xE2\xEE" 

    __step0_suffixes = ('iilor', 'ului', 'elor', 'iile', 'ilor', 

                        'atei', 'a\u0163ie', 'a\u0163ia', 'aua', 

                        'ele', 'iua', 'iei', 'ile', 'ul', 'ea', 

                        'ii') 

    __step1_suffixes = ('abilitate', 'abilitati', 'abilit\u0103\u0163i', 

                        'ibilitate', 'abilit\u0103i', 'ivitate', 

                        'ivitati', 'ivit\u0103\u0163i', 'icitate', 

                        'icitati', 'icit\u0103\u0163i', 'icatori', 

                        'ivit\u0103i', 'icit\u0103i', 'icator', 

                        'a\u0163iune', 'atoare', '\u0103toare', 

                        'i\u0163iune', 'itoare', 'iciva', 'icive', 

                        'icivi', 'iciv\u0103', 'icala', 'icale', 

                        'icali', 'ical\u0103', 'ativa', 'ative', 

                        'ativi', 'ativ\u0103', 'atori', '\u0103tori', 

                        'itiva', 'itive', 'itivi', 'itiv\u0103', 

                        'itori', 'iciv', 'ical', 'ativ', 'ator', 

                        '\u0103tor', 'itiv', 'itor') 

    __step2_suffixes = ('abila', 'abile', 'abili', 'abil\u0103', 

                        'ibila', 'ibile', 'ibili', 'ibil\u0103', 

                        'atori', 'itate', 'itati', 'it\u0103\u0163i', 

                        'abil', 'ibil', 'oasa', 'oas\u0103', 'oase', 

                        'anta', 'ante', 'anti', 'ant\u0103', 'ator', 

                        'it\u0103i', 'iune', 'iuni', 'isme', 'ista', 

                        'iste', 'isti', 'ist\u0103', 'i\u015Fti', 

                        'ata', 'at\u0103', 'ati', 'ate', 'uta', 

                        'ut\u0103', 'uti', 'ute', 'ita', 'it\u0103', 

                        'iti', 'ite', 'ica', 'ice', 'ici', 'ic\u0103', 

                        'osi', 'o\u015Fi', 'ant', 'iva', 'ive', 'ivi', 

                        'iv\u0103', 'ism', 'ist', 'at', 'ut', 'it', 

                        'ic', 'os', 'iv') 

    __step3_suffixes = ('seser\u0103\u0163i', 'aser\u0103\u0163i', 

                        'iser\u0103\u0163i', '\xE2ser\u0103\u0163i', 

                        'user\u0103\u0163i', 'seser\u0103m', 

                        'aser\u0103m', 'iser\u0103m', '\xE2ser\u0103m', 

                        'user\u0103m', 'ser\u0103\u0163i', 'sese\u015Fi', 

                        'seser\u0103', 'easc\u0103', 'ar\u0103\u0163i', 

                        'ur\u0103\u0163i', 'ir\u0103\u0163i', 

                        '\xE2r\u0103\u0163i', 'ase\u015Fi', 

                        'aser\u0103', 'ise\u015Fi', 'iser\u0103', 

                        '\xe2se\u015Fi', '\xE2ser\u0103', 

                        'use\u015Fi', 'user\u0103', 'ser\u0103m', 

                        'sesem', 'indu', '\xE2ndu', 'eaz\u0103', 

                        'e\u015Fti', 'e\u015Fte', '\u0103\u015Fti', 

                        '\u0103\u015Fte', 'ea\u0163i', 'ia\u0163i', 

                        'ar\u0103m', 'ur\u0103m', 'ir\u0103m', 

                        '\xE2r\u0103m', 'asem', 'isem', 

                        '\xE2sem', 'usem', 'se\u015Fi', 'ser\u0103', 

                        'sese', 'are', 'ere', 'ire', '\xE2re', 

                        'ind', '\xE2nd', 'eze', 'ezi', 'esc', 

                        '\u0103sc', 'eam', 'eai', 'eau', 'iam', 

                        'iai', 'iau', 'a\u015Fi', 'ar\u0103', 

                        'u\u015Fi', 'ur\u0103', 'i\u015Fi', 'ir\u0103', 

                        '\xE2\u015Fi', '\xe2r\u0103', 'ase', 

                        'ise', '\xE2se', 'use', 'a\u0163i', 

                        'e\u0163i', 'i\u0163i', '\xe2\u0163i', 'sei', 

                        'ez', 'am', 'ai', 'au', 'ea', 'ia', 'ui', 

                        '\xE2i', '\u0103m', 'em', 'im', '\xE2m', 

                        'se') 

 

    def stem(self, word): 

        """ 

        Stem a Romanian word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        step1_success = False 

        step2_success = False 

 

        for i in range(1, len(word)-1): 

            if word[i-1] in self.__vowels and word[i+1] in self.__vowels: 

                if word[i] == "u": 

                    word = "".join((word[:i], "U", word[i+1:])) 

 

                elif word[i] == "i": 

                    word = "".join((word[:i], "I", word[i+1:])) 

 

        r1, r2 = self._r1r2_standard(word, self.__vowels) 

        rv = self._rv_standard(word, self.__vowels) 

 

        # STEP 0: Removal of plurals and other simplifications 

        for suffix in self.__step0_suffixes: 

            if word.endswith(suffix): 

                if suffix in r1: 

                    if suffix in ("ul", "ului"): 

                        word = word[:-len(suffix)] 

 

                        if suffix in rv: 

                            rv = rv[:-len(suffix)] 

                        else: 

                            rv = "" 

 

                    elif (suffix == "aua" or suffix == "atei" or 

                          (suffix == "ile" and word[-5:-3] != "ab")): 

                        word = word[:-2] 

 

                    elif suffix in ("ea", "ele", "elor"): 

                        word = "".join((word[:-len(suffix)], "e")) 

 

                        if suffix in rv: 

                            rv = "".join((rv[:-len(suffix)], "e")) 

                        else: 

                            rv = "" 

 

                    elif suffix in ("ii", "iua", "iei", 

                                    "iile", "iilor", "ilor"): 

                        word = "".join((word[:-len(suffix)], "i")) 

 

                        if suffix in rv: 

                            rv = "".join((rv[:-len(suffix)], "i")) 

                        else: 

                            rv = "" 

 

                    elif suffix in ("a\u0163ie", "a\u0163ia"): 

                        word = word[:-1] 

                break 

 

        # STEP 1: Reduction of combining suffixes 

        while True: 

 

            replacement_done = False 

 

            for suffix in self.__step1_suffixes: 

                if word.endswith(suffix): 

                    if suffix in r1: 

                        step1_success = True 

                        replacement_done = True 

 

                        if suffix in ("abilitate", "abilitati", 

                                      "abilit\u0103i", 

                                      "abilit\u0103\u0163i"): 

                            word = "".join((word[:-len(suffix)], "abil")) 

 

                        elif suffix == "ibilitate": 

                            word = word[:-5] 

 

                        elif suffix in ("ivitate", "ivitati", 

                                        "ivit\u0103i", 

                                        "ivit\u0103\u0163i"): 

                            word = "".join((word[:-len(suffix)], "iv")) 

 

                        elif suffix in ("icitate", "icitati", "icit\u0103i", 

                                        "icit\u0103\u0163i", "icator", 

                                        "icatori", "iciv", "iciva", 

                                        "icive", "icivi", "iciv\u0103", 

                                        "ical", "icala", "icale", "icali", 

                                        "ical\u0103"): 

                            word = "".join((word[:-len(suffix)], "ic")) 

 

                        elif suffix in ("ativ", "ativa", "ative", "ativi", 

                                        "ativ\u0103", "a\u0163iune", 

                                        "atoare", "ator", "atori", 

                                        "\u0103toare", 

                                        "\u0103tor", "\u0103tori"): 

                            word = "".join((word[:-len(suffix)], "at")) 

 

                            if suffix in r2: 

                                r2 = "".join((r2[:-len(suffix)], "at")) 

 

                        elif suffix in ("itiv", "itiva", "itive", "itivi", 

                                        "itiv\u0103", "i\u0163iune", 

                                        "itoare", "itor", "itori"): 

                            word = "".join((word[:-len(suffix)], "it")) 

 

                            if suffix in r2: 

                                r2 = "".join((r2[:-len(suffix)], "it")) 

                    else: 

                        step1_success = False 

                    break 

 

            if not replacement_done: 

                break 

 

        # STEP 2: Removal of standard suffixes 

        for suffix in self.__step2_suffixes: 

            if word.endswith(suffix): 

                if suffix in r2: 

                    step2_success = True 

 

                    if suffix in ("iune", "iuni"): 

                        if word[-5] == "\u0163": 

                            word = "".join((word[:-5], "t")) 

 

                    elif suffix in ("ism", "isme", "ist", "ista", "iste", 

                                    "isti", "ist\u0103", "i\u015Fti"): 

                        word = "".join((word[:-len(suffix)], "ist")) 

 

                    else: 

                        word = word[:-len(suffix)] 

                break 

 

        # STEP 3: Removal of verb suffixes 

        if not step1_success and not step2_success: 

            for suffix in self.__step3_suffixes: 

                if word.endswith(suffix): 

                    if suffix in rv: 

                        if suffix in ('seser\u0103\u0163i', 'seser\u0103m', 

                                      'ser\u0103\u0163i', 'sese\u015Fi', 

                                      'seser\u0103', 'ser\u0103m', 'sesem', 

                                      'se\u015Fi', 'ser\u0103', 'sese', 

                                      'a\u0163i', 'e\u0163i', 'i\u0163i', 

                                      '\xE2\u0163i', 'sei', '\u0103m', 

                                      'em', 'im', '\xE2m', 'se'): 

                            word = word[:-len(suffix)] 

                            rv = rv[:-len(suffix)] 

                        else: 

                            if (not rv.startswith(suffix) and 

                                rv[rv.index(suffix)-1] not in 

                                "aeio\u0103\xE2\xEE"): 

                                word = word[:-len(suffix)] 

                        break 

 

        # STEP 4: Removal of final vowel 

        for suffix in ("ie", "a", "e", "i", "\u0103"): 

            if word.endswith(suffix): 

                if suffix in rv: 

                    word = word[:-len(suffix)] 

                break 

 

        word = word.replace("I", "i").replace("U", "u") 

 

 

        return word 

 

 

 

class RussianStemmer(_LanguageSpecificStemmer): 

 

    """ 

    The Russian Snowball stemmer. 

 

    :cvar __perfective_gerund_suffixes: Suffixes to be deleted. 

    :type __perfective_gerund_suffixes: tuple 

    :cvar __adjectival_suffixes: Suffixes to be deleted. 

    :type __adjectival_suffixes: tuple 

    :cvar __reflexive_suffixes: Suffixes to be deleted. 

    :type __reflexive_suffixes: tuple 

    :cvar __verb_suffixes: Suffixes to be deleted. 

    :type __verb_suffixes: tuple 

    :cvar __noun_suffixes: Suffixes to be deleted. 

    :type __noun_suffixes: tuple 

    :cvar __superlative_suffixes: Suffixes to be deleted. 

    :type __superlative_suffixes: tuple 

    :cvar __derivational_suffixes: Suffixes to be deleted. 

    :type __derivational_suffixes: tuple 

    :note: A detailed description of the Russian 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/russian/stemmer.html 

 

    """ 

 

    __perfective_gerund_suffixes = ("ivshis'", "yvshis'", "vshis'", 

                                      "ivshi", "yvshi", "vshi", "iv", 

                                      "yv", "v") 

    __adjectival_suffixes = ('ui^ushchi^ui^u', 'ui^ushchi^ai^a', 

                               'ui^ushchimi', 'ui^ushchymi', 'ui^ushchego', 

                               'ui^ushchogo', 'ui^ushchemu', 'ui^ushchomu', 

                               'ui^ushchikh', 'ui^ushchykh', 

                               'ui^ushchui^u', 'ui^ushchaia', 

                               'ui^ushchoi^u', 'ui^ushchei^u', 

                               'i^ushchi^ui^u', 'i^ushchi^ai^a', 

                               'ui^ushchee', 'ui^ushchie', 

                               'ui^ushchye', 'ui^ushchoe', 'ui^ushchei`', 

                               'ui^ushchii`', 'ui^ushchyi`', 

                               'ui^ushchoi`', 'ui^ushchem', 'ui^ushchim', 

                               'ui^ushchym', 'ui^ushchom', 'i^ushchimi', 

                               'i^ushchymi', 'i^ushchego', 'i^ushchogo', 

                               'i^ushchemu', 'i^ushchomu', 'i^ushchikh', 

                               'i^ushchykh', 'i^ushchui^u', 'i^ushchai^a', 

                               'i^ushchoi^u', 'i^ushchei^u', 'i^ushchee', 

                               'i^ushchie', 'i^ushchye', 'i^ushchoe', 

                               'i^ushchei`', 'i^ushchii`', 

                               'i^ushchyi`', 'i^ushchoi`', 'i^ushchem', 

                               'i^ushchim', 'i^ushchym', 'i^ushchom', 

                               'shchi^ui^u', 'shchi^ai^a', 'ivshi^ui^u', 

                               'ivshi^ai^a', 'yvshi^ui^u', 'yvshi^ai^a', 

                               'shchimi', 'shchymi', 'shchego', 'shchogo', 

                               'shchemu', 'shchomu', 'shchikh', 'shchykh', 

                               'shchui^u', 'shchai^a', 'shchoi^u', 

                               'shchei^u', 'ivshimi', 'ivshymi', 

                               'ivshego', 'ivshogo', 'ivshemu', 'ivshomu', 

                               'ivshikh', 'ivshykh', 'ivshui^u', 

                               'ivshai^a', 'ivshoi^u', 'ivshei^u', 

                               'yvshimi', 'yvshymi', 'yvshego', 'yvshogo', 

                               'yvshemu', 'yvshomu', 'yvshikh', 'yvshykh', 

                               'yvshui^u', 'yvshai^a', 'yvshoi^u', 

                               'yvshei^u', 'vshi^ui^u', 'vshi^ai^a', 

                               'shchee', 'shchie', 'shchye', 'shchoe', 

                               'shchei`', 'shchii`', 'shchyi`', 'shchoi`', 

                               'shchem', 'shchim', 'shchym', 'shchom', 

                               'ivshee', 'ivshie', 'ivshye', 'ivshoe', 

                               'ivshei`', 'ivshii`', 'ivshyi`', 

                               'ivshoi`', 'ivshem', 'ivshim', 'ivshym', 

                               'ivshom', 'yvshee', 'yvshie', 'yvshye', 

                               'yvshoe', 'yvshei`', 'yvshii`', 

                               'yvshyi`', 'yvshoi`', 'yvshem', 

                               'yvshim', 'yvshym', 'yvshom', 'vshimi', 

                               'vshymi', 'vshego', 'vshogo', 'vshemu', 

                               'vshomu', 'vshikh', 'vshykh', 'vshui^u', 

                               'vshai^a', 'vshoi^u', 'vshei^u', 

                               'emi^ui^u', 'emi^ai^a', 'nni^ui^u', 

                               'nni^ai^a', 'vshee', 

                               'vshie', 'vshye', 'vshoe', 'vshei`', 

                               'vshii`', 'vshyi`', 'vshoi`', 

                               'vshem', 'vshim', 'vshym', 'vshom', 

                               'emimi', 'emymi', 'emego', 'emogo', 

                               'ememu', 'emomu', 'emikh', 'emykh', 

                               'emui^u', 'emai^a', 'emoi^u', 'emei^u', 

                               'nnimi', 'nnymi', 'nnego', 'nnogo', 

                               'nnemu', 'nnomu', 'nnikh', 'nnykh', 

                               'nnui^u', 'nnai^a', 'nnoi^u', 'nnei^u', 

                               'emee', 'emie', 'emye', 'emoe', 

                               'emei`', 'emii`', 'emyi`', 

                               'emoi`', 'emem', 'emim', 'emym', 

                               'emom', 'nnee', 'nnie', 'nnye', 'nnoe', 

                               'nnei`', 'nnii`', 'nnyi`', 

                               'nnoi`', 'nnem', 'nnim', 'nnym', 

                               'nnom', 'i^ui^u', 'i^ai^a', 'imi', 'ymi', 

                               'ego', 'ogo', 'emu', 'omu', 'ikh', 

                               'ykh', 'ui^u', 'ai^a', 'oi^u', 'ei^u', 

                               'ee', 'ie', 'ye', 'oe', 'ei`', 

                               'ii`', 'yi`', 'oi`', 'em', 

                               'im', 'ym', 'om') 

    __reflexive_suffixes = ("si^a", "s'") 

    __verb_suffixes = ("esh'", 'ei`te', 'ui`te', 'ui^ut', 

                         "ish'", 'ete', 'i`te', 'i^ut', 'nno', 

                         'ila', 'yla', 'ena', 'ite', 'ili', 'yli', 

                         'ilo', 'ylo', 'eno', 'i^at', 'uet', 'eny', 

                         "it'", "yt'", 'ui^u', 'la', 'na', 'li', 

                         'em', 'lo', 'no', 'et', 'ny', "t'", 

                         'ei`', 'ui`', 'il', 'yl', 'im', 

                         'ym', 'en', 'it', 'yt', 'i^u', 'i`', 

                         'l', 'n') 

    __noun_suffixes = ('ii^ami', 'ii^akh', 'i^ami', 'ii^am', 'i^akh', 

                         'ami', 'iei`', 'i^am', 'iem', 'akh', 

                         'ii^u', "'i^u", 'ii^a', "'i^a", 'ev', 'ov', 

                         'ie', "'e", 'ei', 'ii', 'ei`', 

                         'oi`', 'ii`', 'em', 'am', 'om', 

                         'i^u', 'i^a', 'a', 'e', 'i', 'i`', 

                         'o', 'u', 'y', "'") 

    __superlative_suffixes = ("ei`she", "ei`sh") 

    __derivational_suffixes = ("ost'", "ost") 

 

    def stem(self, word): 

        """ 

        Stem a Russian word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        if word in self.stopwords: 

            return word 

 

        chr_exceeded = False 

        for i in range(len(word)): 

            if ord(word[i]) > 255: 

                chr_exceeded = True 

                break 

 

        if chr_exceeded: 

            word = self.__cyrillic_to_roman(word) 

 

        step1_success = False 

        adjectival_removed = False 

        verb_removed = False 

        undouble_success = False 

        superlative_removed = False 

 

        rv, r2 = self.__regions_russian(word) 

 

        # Step 1 

        for suffix in self.__perfective_gerund_suffixes: 

            if rv.endswith(suffix): 

                if suffix in ("v", "vshi", "vshis'"): 

                    if (rv[-len(suffix)-3:-len(suffix)] == "i^a" or 

                        rv[-len(suffix)-1:-len(suffix)] == "a"): 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                        step1_success = True 

                        break 

                else: 

                    word = word[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

                    step1_success = True 

                    break 

 

        if not step1_success: 

            for suffix in self.__reflexive_suffixes: 

                if rv.endswith(suffix): 

                    word = word[:-len(suffix)] 

                    r2 = r2[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

                    break 

 

            for suffix in self.__adjectival_suffixes: 

                if rv.endswith(suffix): 

                    if suffix in ('i^ushchi^ui^u', 'i^ushchi^ai^a', 

                              'i^ushchui^u', 'i^ushchai^a', 'i^ushchoi^u', 

                              'i^ushchei^u', 'i^ushchimi', 'i^ushchymi', 

                              'i^ushchego', 'i^ushchogo', 'i^ushchemu', 

                              'i^ushchomu', 'i^ushchikh', 'i^ushchykh', 

                              'shchi^ui^u', 'shchi^ai^a', 'i^ushchee', 

                              'i^ushchie', 'i^ushchye', 'i^ushchoe', 

                              'i^ushchei`', 'i^ushchii`', 'i^ushchyi`', 

                              'i^ushchoi`', 'i^ushchem', 'i^ushchim', 

                              'i^ushchym', 'i^ushchom', 'vshi^ui^u', 

                              'vshi^ai^a', 'shchui^u', 'shchai^a', 

                              'shchoi^u', 'shchei^u', 'emi^ui^u', 

                              'emi^ai^a', 'nni^ui^u', 'nni^ai^a', 

                              'shchimi', 'shchymi', 'shchego', 'shchogo', 

                              'shchemu', 'shchomu', 'shchikh', 'shchykh', 

                              'vshui^u', 'vshai^a', 'vshoi^u', 'vshei^u', 

                              'shchee', 'shchie', 'shchye', 'shchoe', 

                              'shchei`', 'shchii`', 'shchyi`', 'shchoi`', 

                              'shchem', 'shchim', 'shchym', 'shchom', 

                              'vshimi', 'vshymi', 'vshego', 'vshogo', 

                              'vshemu', 'vshomu', 'vshikh', 'vshykh', 

                              'emui^u', 'emai^a', 'emoi^u', 'emei^u', 

                              'nnui^u', 'nnai^a', 'nnoi^u', 'nnei^u', 

                              'vshee', 'vshie', 'vshye', 'vshoe', 

                              'vshei`', 'vshii`', 'vshyi`', 'vshoi`', 

                              'vshem', 'vshim', 'vshym', 'vshom', 

                              'emimi', 'emymi', 'emego', 'emogo', 

                              'ememu', 'emomu', 'emikh', 'emykh', 

                              'nnimi', 'nnymi', 'nnego', 'nnogo', 

                              'nnemu', 'nnomu', 'nnikh', 'nnykh', 

                              'emee', 'emie', 'emye', 'emoe', 'emei`', 

                              'emii`', 'emyi`', 'emoi`', 'emem', 'emim', 

                              'emym', 'emom', 'nnee', 'nnie', 'nnye', 

                              'nnoe', 'nnei`', 'nnii`', 'nnyi`', 'nnoi`', 

                              'nnem', 'nnim', 'nnym', 'nnom'): 

                        if (rv[-len(suffix)-3:-len(suffix)] == "i^a" or 

                            rv[-len(suffix)-1:-len(suffix)] == "a"): 

                            word = word[:-len(suffix)] 

                            r2 = r2[:-len(suffix)] 

                            rv = rv[:-len(suffix)] 

                            adjectival_removed = True 

                            break 

                    else: 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                        adjectival_removed = True 

                        break 

 

            if not adjectival_removed: 

                for suffix in self.__verb_suffixes: 

                    if rv.endswith(suffix): 

                        if suffix in ("la", "na", "ete", "i`te", "li", 

                                      "i`", "l", "em", "n", "lo", "no", 

                                      "et", "i^ut", "ny", "t'", "esh'", 

                                      "nno"): 

                            if (rv[-len(suffix)-3:-len(suffix)] == "i^a" or 

                                rv[-len(suffix)-1:-len(suffix)] == "a"): 

                                word = word[:-len(suffix)] 

                                r2 = r2[:-len(suffix)] 

                                rv = rv[:-len(suffix)] 

                                verb_removed = True 

                                break 

                        else: 

                            word = word[:-len(suffix)] 

                            r2 = r2[:-len(suffix)] 

                            rv = rv[:-len(suffix)] 

                            verb_removed = True 

                            break 

 

            if not adjectival_removed and not verb_removed: 

                for suffix in self.__noun_suffixes: 

                    if rv.endswith(suffix): 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                        break 

 

        # Step 2 

        if rv.endswith("i"): 

            word = word[:-1] 

            r2 = r2[:-1] 

 

        # Step 3 

        for suffix in self.__derivational_suffixes: 

            if r2.endswith(suffix): 

                word = word[:-len(suffix)] 

                break 

 

        # Step 4 

        if word.endswith("nn"): 

            word = word[:-1] 

            undouble_success = True 

 

        if not undouble_success: 

            for suffix in self.__superlative_suffixes: 

                if word.endswith(suffix): 

                    word = word[:-len(suffix)] 

                    superlative_removed = True 

                    break 

            if word.endswith("nn"): 

                word = word[:-1] 

 

        if not undouble_success and not superlative_removed: 

            if word.endswith("'"): 

                word = word[:-1] 

 

        if chr_exceeded: 

            word = self.__roman_to_cyrillic(word) 

 

 

        return word 

 

 

 

    def __regions_russian(self, word): 

        """ 

        Return the regions RV and R2 which are used by the Russian stemmer. 

 

        In any word, RV is the region after the first vowel, 

        or the end of the word if it contains no vowel. 

 

        R2 is the region after the first non-vowel following 

        a vowel in R1, or the end of the word if there is no such non-vowel. 

 

        R1 is the region after the first non-vowel following a vowel, 

        or the end of the word if there is no such non-vowel. 

 

        :param word: The Russian word whose regions RV and R2 are determined. 

        :type word: str or unicode 

        :return: the regions RV and R2 for the respective Russian word. 

        :rtype: tuple 

        :note: This helper method is invoked by the stem method of the subclass 

               RussianStemmer. It is not to be invoked directly! 

 

        """ 

        r1 = "" 

        r2 = "" 

        rv = "" 

 

        vowels = ("A", "U", "E", "a", "e", "i", "o", "u", "y") 

        word = (word.replace("i^a", "A") 

                    .replace("i^u", "U") 

                    .replace("e`", "E")) 

 

        for i in range(1, len(word)): 

            if word[i] not in vowels and word[i-1] in vowels: 

                r1 = word[i+1:] 

                break 

 

        for i in range(1, len(r1)): 

            if r1[i] not in vowels and r1[i-1] in vowels: 

                r2 = r1[i+1:] 

                break 

 

        for i in range(len(word)): 

            if word[i] in vowels: 

                rv = word[i+1:] 

                break 

 

        r2 = (r2.replace("A", "i^a") 

                .replace("U", "i^u") 

                .replace("E", "e`")) 

        rv = (rv.replace("A", "i^a") 

              .replace("U", "i^u") 

              .replace("E", "e`")) 

 

 

        return (rv, r2) 

 

 

 

    def __cyrillic_to_roman(self, word): 

        """ 

        Transliterate a Russian word into the Roman alphabet. 

 

        A Russian word whose letters consist of the Cyrillic 

        alphabet are transliterated into the Roman alphabet 

        in order to ease the forthcoming stemming process. 

 

        :param word: The word that is transliterated. 

        :type word: unicode 

        :return: the transliterated word. 

        :rtype: unicode 

        :note: This helper method is invoked by the stem method of the subclass 

               RussianStemmer. It is not to be invoked directly! 

 

        """ 

        word = (word.replace("\u0410", "a").replace("\u0430", "a") 

                    .replace("\u0411", "b").replace("\u0431", "b") 

                    .replace("\u0412", "v").replace("\u0432", "v") 

                    .replace("\u0413", "g").replace("\u0433", "g") 

                    .replace("\u0414", "d").replace("\u0434", "d") 

                    .replace("\u0415", "e").replace("\u0435", "e") 

                    .replace("\u0401", "e").replace("\u0451", "e") 

                    .replace("\u0416", "zh").replace("\u0436", "zh") 

                    .replace("\u0417", "z").replace("\u0437", "z") 

                    .replace("\u0418", "i").replace("\u0438", "i") 

                    .replace("\u0419", "i`").replace("\u0439", "i`") 

                    .replace("\u041A", "k").replace("\u043A", "k") 

                    .replace("\u041B", "l").replace("\u043B", "l") 

                    .replace("\u041C", "m").replace("\u043C", "m") 

                    .replace("\u041D", "n").replace("\u043D", "n") 

                    .replace("\u041E", "o").replace("\u043E", "o") 

                    .replace("\u041F", "p").replace("\u043F", "p") 

                    .replace("\u0420", "r").replace("\u0440", "r") 

                    .replace("\u0421", "s").replace("\u0441", "s") 

                    .replace("\u0422", "t").replace("\u0442", "t") 

                    .replace("\u0423", "u").replace("\u0443", "u") 

                    .replace("\u0424", "f").replace("\u0444", "f") 

                    .replace("\u0425", "kh").replace("\u0445", "kh") 

                    .replace("\u0426", "t^s").replace("\u0446", "t^s") 

                    .replace("\u0427", "ch").replace("\u0447", "ch") 

                    .replace("\u0428", "sh").replace("\u0448", "sh") 

                    .replace("\u0429", "shch").replace("\u0449", "shch") 

                    .replace("\u042A", "''").replace("\u044A", "''") 

                    .replace("\u042B", "y").replace("\u044B", "y") 

                    .replace("\u042C", "'").replace("\u044C", "'") 

                    .replace("\u042D", "e`").replace("\u044D", "e`") 

                    .replace("\u042E", "i^u").replace("\u044E", "i^u") 

                    .replace("\u042F", "i^a").replace("\u044F", "i^a")) 

 

 

        return word 

 

 

 

    def __roman_to_cyrillic(self, word): 

        """ 

        Transliterate a Russian word back into the Cyrillic alphabet. 

 

        A Russian word formerly transliterated into the Roman alphabet 

        in order to ease the stemming process, is transliterated back 

        into the Cyrillic alphabet, its original form. 

 

        :param word: The word that is transliterated. 

        :type word: str or unicode 

        :return: word, the transliterated word. 

        :rtype: unicode 

        :note: This helper method is invoked by the stem method of the subclass 

               RussianStemmer. It is not to be invoked directly! 

 

        """ 

        word = (word.replace("i^u", "\u044E").replace("i^a", "\u044F") 

                    .replace("shch", "\u0449").replace("kh", "\u0445") 

                    .replace("t^s", "\u0446").replace("ch", "\u0447") 

                    .replace("e`", "\u044D").replace("i`", "\u0439") 

                    .replace("sh", "\u0448").replace("k", "\u043A") 

                    .replace("e", "\u0435").replace("zh", "\u0436") 

                    .replace("a", "\u0430").replace("b", "\u0431") 

                    .replace("v", "\u0432").replace("g", "\u0433") 

                    .replace("d", "\u0434").replace("e", "\u0435") 

                    .replace("z", "\u0437").replace("i", "\u0438") 

                    .replace("l", "\u043B").replace("m", "\u043C") 

                    .replace("n", "\u043D").replace("o", "\u043E") 

                    .replace("p", "\u043F").replace("r", "\u0440") 

                    .replace("s", "\u0441").replace("t", "\u0442") 

                    .replace("u", "\u0443").replace("f", "\u0444") 

                    .replace("''", "\u044A").replace("y", "\u044B") 

                    .replace("'", "\u044C")) 

 

 

        return word 

 

 

 

class SpanishStemmer(_StandardStemmer): 

 

    """ 

    The Spanish Snowball stemmer. 

 

    :cvar __vowels: The Spanish vowels. 

    :type __vowels: unicode 

    :cvar __step0_suffixes: Suffixes to be deleted in step 0 of the algorithm. 

    :type __step0_suffixes: tuple 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2a_suffixes: Suffixes to be deleted in step 2a of the algorithm. 

    :type __step2a_suffixes: tuple 

    :cvar __step2b_suffixes: Suffixes to be deleted in step 2b of the algorithm. 

    :type __step2b_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :note: A detailed description of the Spanish 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/spanish/stemmer.html 

 

    """ 

 

    __vowels = "aeiou\xE1\xE9\xED\xF3\xFA\xFC" 

    __step0_suffixes = ("selas", "selos", "sela", "selo", "las", 

                        "les", "los", "nos", "me", "se", "la", "le", 

                        "lo") 

    __step1_suffixes = ('amientos', 'imientos', 'amiento', 'imiento', 

                        'aciones', 'uciones', 'adoras', 'adores', 

                        'ancias', 'log\xEDas', 'encias', 'amente', 

                        'idades', 'anzas', 'ismos', 'ables', 'ibles', 

                        'istas', 'adora', 'aci\xF3n', 'antes', 

                        'ancia', 'log\xEDa', 'uci\xf3n', 'encia', 

                        'mente', 'anza', 'icos', 'icas', 'ismo', 

                        'able', 'ible', 'ista', 'osos', 'osas', 

                        'ador', 'ante', 'idad', 'ivas', 'ivos', 

                        'ico', 

                        'ica', 'oso', 'osa', 'iva', 'ivo') 

    __step2a_suffixes = ('yeron', 'yendo', 'yamos', 'yais', 'yan', 

                         'yen', 'yas', 'yes', 'ya', 'ye', 'yo', 

                         'y\xF3') 

    __step2b_suffixes = ('ar\xEDamos', 'er\xEDamos', 'ir\xEDamos', 

                         'i\xE9ramos', 'i\xE9semos', 'ar\xEDais', 

                         'aremos', 'er\xEDais', 'eremos', 

                         'ir\xEDais', 'iremos', 'ierais', 'ieseis', 

                         'asteis', 'isteis', '\xE1bamos', 

                         '\xE1ramos', '\xE1semos', 'ar\xEDan', 

                         'ar\xEDas', 'ar\xE9is', 'er\xEDan', 

                         'er\xEDas', 'er\xE9is', 'ir\xEDan', 

                         'ir\xEDas', 'ir\xE9is', 

                         'ieran', 'iesen', 'ieron', 'iendo', 'ieras', 

                         'ieses', 'abais', 'arais', 'aseis', 

                         '\xE9amos', 'ar\xE1n', 'ar\xE1s', 

                         'ar\xEDa', 'er\xE1n', 'er\xE1s', 

                         'er\xEDa', 'ir\xE1n', 'ir\xE1s', 

                         'ir\xEDa', 'iera', 'iese', 'aste', 'iste', 

                         'aban', 'aran', 'asen', 'aron', 'ando', 

                         'abas', 'adas', 'idas', 'aras', 'ases', 

                         '\xEDais', 'ados', 'idos', 'amos', 'imos', 

                         'emos', 'ar\xE1', 'ar\xE9', 'er\xE1', 

                         'er\xE9', 'ir\xE1', 'ir\xE9', 'aba', 

                         'ada', 'ida', 'ara', 'ase', '\xEDan', 

                         'ado', 'ido', '\xEDas', '\xE1is', 

                         '\xE9is', '\xEDa', 'ad', 'ed', 'id', 

                         'an', 'i\xF3', 'ar', 'er', 'ir', 'as', 

                         '\xEDs', 'en', 'es') 

    __step3_suffixes = ("os", "a", "e", "o", "\xE1", 

                        "\xE9", "\xED", "\xF3") 

 

    def stem(self, word): 

        """ 

        Stem a Spanish word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        step1_success = False 

 

        r1, r2 = self._r1r2_standard(word, self.__vowels) 

        rv = self._rv_standard(word, self.__vowels) 

 

        # STEP 0: Attached pronoun 

        for suffix in self.__step0_suffixes: 

            if word.endswith(suffix): 

                if rv.endswith(suffix): 

                    if rv[:-len(suffix)].endswith(("i\xE9ndo", 

                                                   "\xE1ndo", 

                                                   "\xE1r", "\xE9r", 

                                                   "\xEDr")): 

                        word = (word[:-len(suffix)].replace("\xE1", "a") 

                                                   .replace("\xE9", "e") 

                                                   .replace("\xED", "i")) 

                        r1 = (r1[:-len(suffix)].replace("\xE1", "a") 

                                               .replace("\xE9", "e") 

                                               .replace("\xED", "i")) 

                        r2 = (r2[:-len(suffix)].replace("\xE1", "a") 

                                               .replace("\xE9", "e") 

                                               .replace("\xED", "i")) 

                        rv = (rv[:-len(suffix)].replace("\xE1", "a") 

                                               .replace("\xE9", "e") 

                                               .replace("\xED", "i")) 

 

                    elif rv[:-len(suffix)].endswith(("ando", "iendo", 

                                                     "ar", "er", "ir")): 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

 

                    elif (rv[:-len(suffix)].endswith("yendo") and 

                          word[:-len(suffix)].endswith("uyendo")): 

                        word = word[:-len(suffix)] 

                        r1 = r1[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                break 

 

        # STEP 1: Standard suffix removal 

        for suffix in self.__step1_suffixes: 

            if word.endswith(suffix): 

                if suffix == "amente" and r1.endswith(suffix): 

                    step1_success = True 

                    word = word[:-6] 

                    r2 = r2[:-6] 

                    rv = rv[:-6] 

 

                    if r2.endswith("iv"): 

                        word = word[:-2] 

                        r2 = r2[:-2] 

                        rv = rv[:-2] 

 

                        if r2.endswith("at"): 

                            word = word[:-2] 

                            rv = rv[:-2] 

 

                    elif r2.endswith(("os", "ic", "ad")): 

                        word = word[:-2] 

                        rv = rv[:-2] 

 

                elif r2.endswith(suffix): 

                    step1_success = True 

                    if suffix in ("adora", "ador", "aci\xF3n", "adoras", 

                                  "adores", "aciones", "ante", "antes", 

                                  "ancia", "ancias"): 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

 

                        if r2.endswith("ic"): 

                            word = word[:-2] 

                            rv = rv[:-2] 

 

                    elif suffix in ("log\xEDa", "log\xEDas"): 

                        word = word.replace(suffix, "log") 

                        rv = rv.replace(suffix, "log") 

 

                    elif suffix in ("uci\xF3n", "uciones"): 

                        word = word.replace(suffix, "u") 

                        rv = rv.replace(suffix, "u") 

 

                    elif suffix in ("encia", "encias"): 

                        word = word.replace(suffix, "ente") 

                        rv = rv.replace(suffix, "ente") 

 

                    elif suffix == "mente": 

                        word = word[:-5] 

                        r2 = r2[:-5] 

                        rv = rv[:-5] 

 

                        if r2.endswith(("ante", "able", "ible")): 

                            word = word[:-4] 

                            rv = rv[:-4] 

 

                    elif suffix in ("idad", "idades"): 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

 

                        for pre_suff in ("abil", "ic", "iv"): 

                            if r2.endswith(pre_suff): 

                                word = word[:-len(pre_suff)] 

                                rv = rv[:-len(pre_suff)] 

 

                    elif suffix in ("ivo", "iva", "ivos", "ivas"): 

                        word = word[:-len(suffix)] 

                        r2 = r2[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                        if r2.endswith("at"): 

                            word = word[:-2] 

                            rv = rv[:-2] 

                    else: 

                        word = word[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                break 

 

        # STEP 2a: Verb suffixes beginning 'y' 

        if not step1_success: 

            for suffix in self.__step2a_suffixes: 

                if (rv.endswith(suffix) and 

                    word[-len(suffix)-1:-len(suffix)] == "u"): 

                    word = word[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

                    break 

 

        # STEP 2b: Other verb suffixes 

            for suffix in self.__step2b_suffixes: 

                if rv.endswith(suffix): 

                    if suffix in ("en", "es", "\xE9is", "emos"): 

                        word = word[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

 

                        if word.endswith("gu"): 

                            word = word[:-1] 

 

                        if rv.endswith("gu"): 

                            rv = rv[:-1] 

                    else: 

                        word = word[:-len(suffix)] 

                        rv = rv[:-len(suffix)] 

                    break 

 

        # STEP 3: Residual suffix 

        for suffix in self.__step3_suffixes: 

            if rv.endswith(suffix): 

                if suffix in ("e", "\xE9"): 

                    word = word[:-len(suffix)] 

                    rv = rv[:-len(suffix)] 

 

                    if word[-2:] == "gu" and rv[-1] == "u": 

                        word = word[:-1] 

                else: 

                    word = word[:-len(suffix)] 

                break 

 

        word = (word.replace("\xE1", "a").replace("\xE9", "e") 

                    .replace("\xED", "i").replace("\xF3", "o") 

                    .replace("\xFA", "u")) 

 

 

        return word 

 

 

 

class SwedishStemmer(_ScandinavianStemmer): 

 

    """ 

    The Swedish Snowball stemmer. 

 

    :cvar __vowels: The Swedish vowels. 

    :type __vowels: unicode 

    :cvar __s_ending: Letters that may directly appear before a word final 's'. 

    :type __s_ending: unicode 

    :cvar __step1_suffixes: Suffixes to be deleted in step 1 of the algorithm. 

    :type __step1_suffixes: tuple 

    :cvar __step2_suffixes: Suffixes to be deleted in step 2 of the algorithm. 

    :type __step2_suffixes: tuple 

    :cvar __step3_suffixes: Suffixes to be deleted in step 3 of the algorithm. 

    :type __step3_suffixes: tuple 

    :note: A detailed description of the Swedish 

           stemming algorithm can be found under 

           http://snowball.tartarus.org/algorithms/swedish/stemmer.html 

 

    """ 

 

    __vowels = "aeiouy\xE4\xE5\xF6" 

    __s_ending = "bcdfghjklmnoprtvy" 

    __step1_suffixes = ("heterna", "hetens", "heter", "heten", 

                        "anden", "arnas", "ernas", "ornas", "andes", 

                        "andet", "arens", "arna", "erna", "orna", 

                        "ande", "arne", "aste", "aren", "ades", 

                        "erns", "ade", "are", "ern", "ens", "het", 

                        "ast", "ad", "en", "ar", "er", "or", "as", 

                        "es", "at", "a", "e", "s") 

    __step2_suffixes = ("dd", "gd", "nn", "dt", "gt", "kt", "tt") 

    __step3_suffixes = ("fullt", "l\xF6st", "els", "lig", "ig") 

 

    def stem(self, word): 

        """ 

        Stem a Swedish word and return the stemmed form. 

 

        :param word: The word that is stemmed. 

        :type word: str or unicode 

        :return: The stemmed form. 

        :rtype: unicode 

 

        """ 

        word = word.lower() 

 

        if word in self.stopwords: 

            return word 

 

        r1 = self._r1_scandinavian(word, self.__vowels) 

 

        # STEP 1 

        for suffix in self.__step1_suffixes: 

            if r1.endswith(suffix): 

                if suffix == "s": 

                    if word[-2] in self.__s_ending: 

                        word = word[:-1] 

                        r1 = r1[:-1] 

                else: 

                    word = word[:-len(suffix)] 

                    r1 = r1[:-len(suffix)] 

                break 

 

        # STEP 2 

        for suffix in self.__step2_suffixes: 

            if r1.endswith(suffix): 

                word = word[:-1] 

                r1 = r1[:-1] 

                break 

 

        # STEP 3 

        for suffix in self.__step3_suffixes: 

            if r1.endswith(suffix): 

                if suffix in ("els", "lig", "ig"): 

                    word = word[:-len(suffix)] 

                elif suffix in ("fullt", "l\xF6st"): 

                    word = word[:-1] 

                break 

 

 

        return word 

 

 

 

def demo(): 

    """ 

    This function provides a demonstration of the Snowball stemmers. 

 

    After invoking this function and specifying a language, 

    it stems an excerpt of the Universal Declaration of Human Rights 

    (which is a part of the NLTK corpus collection) and then prints 

    out the original and the stemmed text. 

 

    """ 

 

    import re 

    from nltk.corpus import udhr 

 

    udhr_corpus = {"danish":     "Danish_Dansk-Latin1", 

                   "dutch":      "Dutch_Nederlands-Latin1", 

                   "english":    "English-Latin1", 

                   "finnish":    "Finnish_Suomi-Latin1", 

                   "french":     "French_Francais-Latin1", 

                   "german":     "German_Deutsch-Latin1", 

                   "hungarian":  "Hungarian_Magyar-UTF8", 

                   "italian":    "Italian_Italiano-Latin1", 

                   "norwegian":  "Norwegian-Latin1", 

                   "porter":     "English-Latin1", 

                   "portuguese": "Portuguese_Portugues-Latin1", 

                   "romanian":   "Romanian_Romana-Latin2", 

                   "russian":    "Russian-UTF8", 

                   "spanish":    "Spanish-Latin1", 

                   "swedish":    "Swedish_Svenska-Latin1", 

                   } 

 

    print("\n") 

    print("******************************") 

    print("Demo for the Snowball stemmers") 

    print("******************************") 

 

    while True: 

 

        language = raw_input("Please enter the name of the language " + 

                             "to be demonstrated\n" + 

                             "/".join(SnowballStemmer.languages) + 

                             "\n" + 

                             "(enter 'exit' in order to leave): ") 

 

        if language == "exit": 

            break 

 

        if language not in SnowballStemmer.languages: 

            print(("\nOops, there is no stemmer for this language. " + 

                   "Please try again.\n")) 

            continue 

 

        stemmer = SnowballStemmer(language) 

        excerpt = udhr.words(udhr_corpus[language]) [:300] 

 

        stemmed = " ".join([stemmer.stem(word) for word in excerpt]) 

        stemmed = re.sub(r"(.{,70})\s", r'\1\n', stemmed+' ').rstrip() 

        excerpt = " ".join(excerpt) 

        excerpt = re.sub(r"(.{,70})\s", r'\1\n', excerpt+' ').rstrip() 

 

        print("\n") 

        print('-' * 70) 

        print('ORIGINAL'.center(70)) 

        print(excerpt) 

        print("\n\n") 

        print('STEMMED RESULTS'.center(70)) 

        print(stemmed) 

        print('-' * 70) 

        print("\n") 

 

 

 

if __name__ == "__main__": 

    import doctest 

    doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)