├── .gitattributes
├── .gitignore
├── GraphicAlgorithm
├── ArbitraryPolygonCut
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── ArbitraryPolygonCut.cs
│ ├── ArbitraryPolygonCut.csproj
│ ├── ArbitraryPolygonCutTest.cs
│ ├── ArrowLine.cs
│ ├── CrossLine.cs
│ ├── CutFile
│ │ ├── C包含S.cut
│ │ ├── S包含C.cut
│ │ ├── 完全不相交.cut
│ │ ├── 完全不相交(同向).cut
│ │ ├── 底边重合(图6).cut
│ │ ├── 文档示例(S6S7S1特殊).cut
│ │ ├── 文档示例(改C1位置).cut
│ │ ├── 文档示例.cut
│ │ ├── 点在边上重合(图5-右).cut
│ │ └── 点在边上(图5-左).cut
│ ├── CutModel.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── MyPolygon.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── WindowLog.cs
│ └── packages.config
├── Doc
│ └── 示意图.vsd
└── GraphicAlgorithm.sln
├── HadoopNET
├── HadoopNET.sln
├── HadoopNET
│ ├── App.config
│ ├── HadoopNET.csproj
│ ├── MRLib
│ │ ├── MRRunner.exe
│ │ ├── Microsoft.Hadoop.Client.dll
│ │ ├── Microsoft.Hadoop.CombineDriver.exe
│ │ ├── Microsoft.Hadoop.MapDriver.exe
│ │ ├── Microsoft.Hadoop.MapReduce.dll
│ │ ├── Microsoft.Hadoop.ReduceDriver.exe
│ │ └── Microsoft.WindowsAzure.Management.Framework.Threading.dll
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── NetCoreMapper
│ ├── NetCoreMapper.csproj
│ ├── Program.cs
│ └── publish.bat
├── NetCoreReducer
│ ├── NetCoreReducer.csproj
│ ├── Program.cs
│ └── publish.bat
├── NetCreateCluster
│ ├── App.config
│ ├── DeploymentHelper.cs
│ ├── NetCreateCluster.csproj
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── packages.config
│ ├── parameters.json
│ └── template.json
├── NetMapper
│ ├── App.config
│ ├── NetMapper.csproj
│ ├── Program.cs
│ └── Properties
│ │ └── AssemblyInfo.cs
├── NetReducer
│ ├── App.config
│ ├── NetReducer.csproj
│ ├── Program.cs
│ └── Properties
│ │ └── AssemblyInfo.cs
└── SubmitNet
│ ├── App.config
│ ├── Program.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── SubmitNet.csproj
│ └── packages.config
├── PCI
├── PCI.sln
└── PCI
│ ├── AdvancedClassify.cs
│ ├── AdvancedClassifyTest.cs
│ ├── App.config
│ ├── Crawler.cs
│ ├── DecisionNode.cs
│ ├── DocClass.cs
│ ├── Dorm.cs
│ ├── Gp.cs
│ ├── GpTest.cs
│ ├── IClassifier.cs
│ ├── ISimilar.cs
│ ├── LIBSVM_COPYRIGHT
│ ├── Lib
│ └── Python.Runtime.dll
│ ├── MatplotlibCS
│ ├── annotations.py
│ ├── arc.py
│ ├── helpers.py
│ ├── histogram.py
│ ├── hline.py
│ ├── line_2d.py
│ ├── matplotlib_cs.py
│ ├── subplot.py
│ ├── task.py
│ └── vline.py
│ ├── NewsFeatures.cs
│ ├── NewsFeaturesTest.cs
│ ├── Nmf.cs
│ ├── NumPredict.cs
│ ├── NumPredictTest.cs
│ ├── PCI.csproj
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── SearchNet.cs
│ ├── Searcher.cs
│ ├── SocialNetwork.cs
│ ├── TestData
│ ├── agesonly.csv
│ └── matchmaker.csv
│ ├── Travel.cs
│ ├── TravelForNumPredict.cs
│ ├── blogdata.txt
│ ├── libsvm.dll
│ └── packages.config
├── README.md
├── Win81Demo
├── Win81Demo.Controls.Sample
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Assets
│ │ ├── Logo.scale-100.png
│ │ ├── SmallLogo.scale-100.png
│ │ ├── SplashScreen.scale-100.png
│ │ └── StoreLogo.scale-100.png
│ ├── MainPage.xaml
│ ├── MainPage.xaml.cs
│ ├── Package.appxmanifest
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── View
│ │ ├── CircleMenuSample.xaml
│ │ └── CircleMenuSample.xaml.cs
│ ├── ViewModel
│ │ ├── CircleMenuSampleViewModel.cs
│ │ ├── MainViewModel.cs
│ │ └── ViewModelLocator.cs
│ ├── Win81Demo.Controls.Sample.csproj
│ ├── Win81Demo.Controls.Sample_TemporaryKey.pfx
│ └── packages.config
├── Win81Demo.Controls
│ ├── CircleMenuControl
│ │ ├── CircleMenu.cs
│ │ ├── CircleMenu.xaml
│ │ ├── CircleMenuItem.cs
│ │ └── CircleMenuPanel.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Themes
│ │ └── Generic.xaml
│ └── Win81Demo.Controls.csproj
└── Win81Demo.sln
├── WpfDemo
├── Wpf.Control.Sample
│ ├── App.config
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Design
│ │ └── DesignDataService.cs
│ ├── Model
│ │ ├── DataItem.cs
│ │ ├── DataService.cs
│ │ └── IDataService.cs
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ ├── Resources.resx
│ │ ├── Settings.Designer.cs
│ │ └── Settings.settings
│ ├── ViewModel
│ │ ├── CircleMenuSampleViewModel.cs
│ │ ├── FlowSampleViewModel.cs
│ │ ├── MainViewModel.cs
│ │ └── ViewModelLocator.cs
│ ├── Views
│ │ ├── CircleMenuSample.xaml
│ │ ├── CircleMenuSample.xaml.cs
│ │ ├── FlowSample.xaml
│ │ ├── FlowSample.xaml.cs
│ │ ├── MainWindow.xaml
│ │ └── MainWindow.xaml.cs
│ ├── Wpf.Control.Sample.csproj
│ └── packages.config
├── Wpf.Control
│ ├── CircleMenu
│ │ ├── CircleMenuControl.cs
│ │ ├── CircleMenuControl.xaml
│ │ ├── CircleMenuItem.cs
│ │ ├── CircleMenuItemsPresenter.cs
│ │ └── CircleMenuPanel.cs
│ ├── Flow
│ │ ├── FlowControl.cs
│ │ ├── FlowControl.xaml
│ │ ├── FlowControlPanel.cs
│ │ ├── FlowItem.cs
│ │ ├── FlowNodeControl.cs
│ │ ├── FlowNodeControl.xaml
│ │ ├── MultiMarginConverter.cs
│ │ ├── MultiWidthAnimationConverter.cs
│ │ └── TitleMaxWidthConverter.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Themes
│ │ └── Generic.xaml
│ └── Wpf.Control.csproj
└── WpfControlDemo.sln
└── XMindFiles
└── WPF.xmind
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace WpfApplication1
10 | {
11 | ///
12 | /// App.xaml 的交互逻辑
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CrossLine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Media;
8 | using System.Windows.Shapes;
9 |
10 | namespace WpfApplication1
11 | {
12 | public class CrossLine : Shape
13 | {
14 | public static readonly DependencyProperty CenterProperty = DependencyProperty.Register(
15 | "Center", typeof(Point), typeof(CrossLine),
16 | new FrameworkPropertyMetadata(default(Point), FrameworkPropertyMetadataOptions.AffectsRender));
17 |
18 | public Point Center
19 | {
20 | get { return (Point)GetValue(CenterProperty); }
21 | set { SetValue(CenterProperty, value); }
22 | }
23 |
24 | public static readonly DependencyProperty VisibleProperty = DependencyProperty.Register(
25 | "Visible", typeof(bool), typeof(CrossLine),
26 | new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
27 |
28 | public bool Visible
29 | {
30 | get { return (bool)GetValue(VisibleProperty); }
31 | set { SetValue(VisibleProperty, value); }
32 | }
33 |
34 | public static readonly DependencyProperty CrossRadiusProperty = DependencyProperty.Register(
35 | "CrossRadius", typeof(double), typeof(CrossLine), new PropertyMetadata(3d));
36 |
37 | public double CrossRadius
38 | {
39 | get { return (double)GetValue(CrossRadiusProperty); }
40 | set { SetValue(CrossRadiusProperty, value); }
41 | }
42 |
43 | private Geometry _polylineGeometry;
44 |
45 | protected override Geometry DefiningGeometry
46 | {
47 | get
48 | {
49 | CompositeGeometry();
50 | return _polylineGeometry;
51 | }
52 | }
53 |
54 | private void CompositeGeometry()
55 | {
56 | if (!Visible)
57 | {
58 | _polylineGeometry = Geometry.Empty;
59 | return;
60 | }
61 |
62 | PathGeometry polylineGeometry = new PathGeometry();
63 |
64 |
65 | var topPoint = new Point(Center.X, Center.Y - CrossRadius);
66 | var bottomPoint = new Point(Center.X, Center.Y + CrossRadius);
67 | PathFigure pathFigureV = new PathFigure();
68 | pathFigureV.StartPoint = topPoint;
69 | pathFigureV.Segments.Add(new LineSegment(bottomPoint, true));
70 | var leftPoint = new Point(Center.X - CrossRadius, Center.Y);
71 | var rightPoint = new Point(Center.X + CrossRadius, Center.Y);
72 | var pathFigureH = new PathFigure();
73 | pathFigureH.StartPoint = leftPoint;
74 | pathFigureH.Segments.Add(new LineSegment(rightPoint, true));
75 | polylineGeometry.Figures.Add(pathFigureV);
76 | polylineGeometry.Figures.Add(pathFigureH);
77 |
78 | // Set FillRule
79 | polylineGeometry.FillRule = FillRule.EvenOdd;
80 |
81 | if (polylineGeometry.Bounds == Rect.Empty)
82 | {
83 | _polylineGeometry = Geometry.Empty;
84 | }
85 | else
86 | {
87 | _polylineGeometry = polylineGeometry;
88 | }
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/C包含S.cut:
--------------------------------------------------------------------------------
1 | [{"X":281.0,"Y":159.0,"Name":"S1"},{"X":242.0,"Y":366.0,"Name":"S2"},{"X":506.0,"Y":419.0,"Name":"S3"},{"X":569.0,"Y":248.0,"Name":"S4"},{"X":472.0,"Y":155.0,"Name":"S5"}]
2 | [{"X":149.0,"Y":241.0,"Name":"C1"},{"X":282.0,"Y":72.0,"Name":"C2"},{"X":559.0,"Y":111.0,"Name":"C3"},{"X":628.0,"Y":406.0,"Name":"C4"},{"X":418.0,"Y":475.0,"Name":"C5"},{"X":170.0,"Y":407.0,"Name":"C6"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/S包含C.cut:
--------------------------------------------------------------------------------
1 | [{"X":259.0,"Y":113.0,"Name":"S1"},{"X":103.0,"Y":374.0,"Name":"S2"},{"X":548.0,"Y":481.0,"Name":"S3"},{"X":689.0,"Y":107.0,"Name":"S4"}]
2 | [{"X":306.0,"Y":178.0,"Name":"C1"},{"X":255.0,"Y":326.0,"Name":"C2"},{"X":441.0,"Y":387.0,"Name":"C3"},{"X":596.0,"Y":263.0,"Name":"C4"},{"X":565.0,"Y":160.0,"Name":"C5"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/完全不相交.cut:
--------------------------------------------------------------------------------
1 | [{"X":94.0,"Y":162.0,"Name":"S1"},{"X":59.0,"Y":352.0,"Name":"S2"},{"X":223.0,"Y":480.0,"Name":"S3"},{"X":393.0,"Y":321.0,"Name":"S4"}]
2 | [{"X":500.0,"Y":98.0,"Name":"C1"},{"X":689.0,"Y":111.0,"Name":"C2"},{"X":732.0,"Y":283.0,"Name":"C3"},{"X":603.0,"Y":413.0,"Name":"C4"},{"X":390.0,"Y":270.0,"Name":"C5"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/完全不相交(同向).cut:
--------------------------------------------------------------------------------
1 | [{"X":79.0,"Y":176.0,"Name":"S1"},{"X":52.0,"Y":429.0,"Name":"S2"},{"X":282.0,"Y":430.0,"Name":"S3"},{"X":341.0,"Y":240.0,"Name":"S4"},{"X":221.0,"Y":169.0,"Name":"S5"}]
2 | [{"X":456.0,"Y":111.0,"Name":"C1"},{"X":413.0,"Y":320.0,"Name":"C2"},{"X":691.0,"Y":287.0,"Name":"C3"},{"X":680.0,"Y":172.0,"Name":"C4"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/底边重合(图6).cut:
--------------------------------------------------------------------------------
1 | [{"X":247.0,"Y":183.0,"Name":"S1"},{"X":129.0,"Y":374.0,"Name":"S2"},{"X":536.0,"Y":374.0,"Name":"S3"},{"X":536.0,"Y":181.0,"Name":"S4"}]
2 | [{"X":128.0,"Y":71.0,"Name":"C1"},{"X":263.0,"Y":374.0,"Name":"C2"},{"X":455.0,"Y":374.0,"Name":"C3"},{"X":295.0,"Y":70.0,"Name":"C4"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/文档示例(S6S7S1特殊).cut:
--------------------------------------------------------------------------------
1 | [{"X":70.0,"Y":104.0,"Name":"S1"},{"X":120.0,"Y":487.0,"Name":"S2"},{"X":688.0,"Y":484.0,"Name":"S3"},{"X":625.0,"Y":299.0,"Name":"S4"},{"X":412.0,"Y":455.0,"Name":"S5"},{"X":281.0,"Y":219.0,"Name":"S6"},{"X":227.0,"Y":357.0,"Name":"S7"}]
2 | [{"X":125.0,"Y":256.0,"Name":"C1"},{"X":689.0,"Y":242.0,"Name":"C2"},{"X":710.0,"Y":427.0,"Name":"C3"},{"X":40.0,"Y":371.0,"Name":"C4"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/文档示例(改C1位置).cut:
--------------------------------------------------------------------------------
1 | [{"Next":null,"X":126.0,"Y":121.0,"Name":"S1"},{"Next":null,"X":169.0,"Y":434.0,"Name":"S2"},{"Next":null,"X":633.0,"Y":442.0,"Name":"S3"},{"Next":null,"X":575.0,"Y":194.0,"Name":"S4"},{"Next":null,"X":335.0,"Y":391.0,"Name":"S5"}]
2 | [{"Next":null,"X":176.0,"Y":234.0,"Name":"C1"},{"Next":null,"X":622.0,"Y":132.0,"Name":"C2"},{"Next":null,"X":656.0,"Y":362.0,"Name":"C3"},{"Next":null,"X":90.0,"Y":328.0,"Name":"C4"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/文档示例.cut:
--------------------------------------------------------------------------------
1 | [{"X":173.0,"Y":106.0,"Name":"S1"},{"X":128.0,"Y":443.0,"Name":"S2"},{"X":663.0,"Y":457.0,"Name":"S3"},{"X":663.0,"Y":232.0,"Name":"S4"},{"X":333.0,"Y":366.0,"Name":"S5"}]
2 | [{"X":81.0,"Y":183.0,"Name":"C1"},{"X":737.0,"Y":179.0,"Name":"C2"},{"X":713.0,"Y":379.0,"Name":"C3"},{"X":59.0,"Y":292.0,"Name":"C4"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/点在边上重合(图5-右).cut:
--------------------------------------------------------------------------------
1 | [{"X":180.0,"Y":115.0,"Name":"S1"},{"X":180.0,"Y":293.0,"Name":"S2"},{"X":378.0,"Y":293.0,"Name":"S3"},{"X":357.0,"Y":115.0,"Name":"S4"}]
2 | [{"X":123.0,"Y":115.0,"Name":"C1"},{"X":304.0,"Y":115.0,"Name":"C2"},{"X":304.0,"Y":232.0,"Name":"C3"},{"X":44.0,"Y":232.0,"Name":"C4"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutFile/点在边上(图5-左).cut:
--------------------------------------------------------------------------------
1 | [{"X":242.0,"Y":78.0,"Name":"S1"},{"X":242.0,"Y":289.0,"Name":"S2"},{"X":480.0,"Y":289.0,"Name":"S3"},{"X":480.0,"Y":77.0,"Name":"S4"}]
2 | [{"X":162.0,"Y":110.0,"Name":"C1"},{"X":162.0,"Y":247.0,"Name":"C2"},{"X":386.0,"Y":103.0,"Name":"C3"},{"X":388.0,"Y":19.0,"Name":"C4"}]
3 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/CutModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using Newtonsoft.Json;
9 |
10 | namespace WpfApplication1
11 | {
12 | [Serializable]
13 | public abstract class VertexBase
14 | {
15 | public double X { get; set; }
16 | public double Y { get; set; }
17 |
18 | public string Name { get; set; }
19 |
20 | public void SetXY(double x, double y)
21 | {
22 | X = x;
23 | Y = y;
24 | }
25 |
26 | public Point ToPoint()
27 | {
28 | return new Point(X,Y);
29 | }
30 | }
31 |
32 | public class Vertex : VertexBase
33 | {
34 | [DebuggerNonUserCode]
35 | public Vertex(double x, double y)
36 | {
37 | X = x;
38 | Y = y;
39 | }
40 |
41 | [JsonIgnore]
42 | public VertexBase Next { get; set; }
43 | }
44 |
45 | public class Intersection : VertexBase
46 | {
47 | [DebuggerNonUserCode]
48 | public Intersection(double x, double y)
49 | {
50 | X = x;
51 | Y = y;
52 | }
53 |
54 | public CrossInOut CrossDi { get; set; }
55 | public bool Used { get; set; }
56 | public VertexBase NextS { get; set; }
57 | public VertexBase NextC { get; set; }
58 | }
59 |
60 | public class IntersWithIndex : Intersection
61 | {
62 | [DebuggerNonUserCode]
63 | public IntersWithIndex(double x, double y, int idx)
64 | : base(x, y)
65 | {
66 | Idx = idx;
67 | }
68 |
69 | public int Idx { get; set; }
70 | }
71 |
72 | public enum CrossInOut
73 | {
74 | In, Out
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 显示方向
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/MyPolygon.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.Linq;
5 | using System.Windows;
6 | using System.Windows.Controls;
7 | using System.Windows.Media;
8 | using System.Windows.Shapes;
9 |
10 | namespace WpfApplication1
11 | {
12 | [Serializable]
13 | public class MyPolygon
14 | {
15 | public MyPolygon(RenderType type = RenderType.Polyline)
16 | {
17 | _type = type;
18 | }
19 |
20 | public Color StrokeColor { get; set; }
21 | public Color FillColor { get; set; }
22 | public double StrokeThickess { get; set; }
23 |
24 | private readonly RenderType _type;
25 | public bool Filled { get; set; } = false;
26 | public bool ShowArrow { get; set; }
27 | public bool ArrowReverse { get; set; }
28 |
29 | public List PointList = new List();
30 | private Shape _innerShape;
31 |
32 | private bool showed = false;
33 |
34 | public void Render(Canvas canvas)
35 | {
36 | if (_type == RenderType.Polyline)
37 | {
38 | if (_innerShape == null)
39 | {
40 | _innerShape = new ArrowLine()
41 | {
42 | Stroke = new SolidColorBrush(StrokeColor),
43 | StrokeThickness = StrokeThickess,
44 | Fill = Filled ? new SolidColorBrush(FillColor) : new SolidColorBrush(Colors.Transparent),
45 | };
46 | }
47 | var polyline = _innerShape as ArrowLine;
48 | polyline.IsDirectionReverse = ArrowReverse;
49 | polyline.ShowArrow = ShowArrow;
50 | polyline.Text = PointList.Select(v => v.Name).ToList();
51 | polyline.Points.Clear();
52 | PointList.ForEach(v=>polyline.Points.Add(v.ToPoint()));
53 | polyline.Points.Add(PointList[0].ToPoint());
54 | }
55 | else if (_type == RenderType.Polygon)
56 | {
57 | if (_innerShape == null)
58 | {
59 | _innerShape = new Polygon()
60 | {
61 | Stroke = new SolidColorBrush(StrokeColor),
62 | StrokeThickness = StrokeThickess,
63 | Fill = Filled ? new SolidColorBrush(FillColor) : new SolidColorBrush(Colors.Transparent)
64 | };
65 | var polygon = _innerShape as Polygon;
66 | polygon.Points.Clear();
67 | PointList.ForEach(pv => polygon.Points.Add(new Point(pv.X, pv.Y)));
68 | polygon.Points.Add(PointList[0].ToPoint());
69 | }
70 | }
71 |
72 | if (!showed)
73 | {
74 | canvas.Children.Add(_innerShape);
75 | showed = true;
76 | }
77 | }
78 |
79 | public void Reset()
80 | {
81 | PointList.Clear();
82 | showed = false;
83 | ArrowReverse = false;
84 | }
85 | }
86 |
87 | public enum RenderType
88 | {
89 | Polyline,
90 | Polygon
91 | }
92 | }
93 |
94 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // 有关程序集的一般信息由以下
8 | // 控制。更改这些特性值可修改
9 | // 与程序集关联的信息。
10 | [assembly: AssemblyTitle("WpfApplication1")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("WpfApplication1")]
15 | [assembly: AssemblyCopyright("Copyright © 2015")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | //将 ComVisible 设置为 false 将使此程序集中的类型
20 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
21 | //请将此类型的 ComVisible 特性设置为 true。
22 | [assembly: ComVisible(false)]
23 |
24 | //若要开始生成可本地化的应用程序,请
25 | // 中的 .csproj 文件中
26 | //例如,如果您在源文件中使用的是美国英语,
27 | //使用的是美国英语,请将 设置为 en-US。 然后取消
28 | //对以下 NeutralResourceLanguage 特性的注释。 更新
29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36 | //(当资源未在页面
37 | //或应用程序资源字典中找到时使用)
38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39 | //(当资源未在页面
40 | //、应用程序或任何主题专用资源字典中找到时使用)
41 | )]
42 |
43 |
44 | // 程序集的版本信息由下列四个值组成:
45 | //
46 | // 主版本
47 | // 次版本
48 | // 生成号
49 | // 修订号
50 | //
51 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
52 | // 方法是按如下所示使用“*”: :
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ArbitraryPolygonCut.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// 一个强类型的资源类,用于查找本地化的字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// 返回此类使用的缓存的 ResourceManager 实例。
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ArbitraryPolygonCut.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// 使用此强类型资源类,为所有资源查找
51 | /// 重写当前线程的 CurrentUICulture 属性。
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本:4.0.30319.42000
5 | //
6 | // 对此文件的更改可能会导致不正确的行为,并且如果
7 | // 重新生成代码,这些更改将会丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace ArbitraryPolygonCut.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/WindowLog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace WpfApplication1
10 | {
11 | public class WindowLog
12 | {
13 | private static WindowLog _logger;
14 | private static readonly object CreationLock = new object();
15 |
16 | public static WindowLog Default
17 | {
18 | get
19 | {
20 |
21 | if (_logger == null)
22 | {
23 | lock (CreationLock)
24 | {
25 | if (_logger == null)
26 | _logger = new WindowLog();
27 | }
28 | }
29 | return _logger;
30 | }
31 | }
32 |
33 | private Action _logComingAction;
34 | private Action _addLabelAction;
35 | private Action _reverseAction;
36 |
37 | public void WhenLogCommon(Action logComingAction)
38 | {
39 | _logComingAction = logComingAction;
40 | }
41 |
42 | public void WhenAddLabel(Action addLabelAction)
43 | {
44 | _addLabelAction = addLabelAction;
45 | }
46 |
47 | public void Log(string log)
48 | {
49 | _logComingAction?.Invoke(log);
50 | Debug.WriteLine(log);
51 | }
52 |
53 | public void Log(string format, params object[] arg)
54 | {
55 | var log = string.Format(format, arg);
56 | Log(log);
57 | }
58 |
59 | public void AddLabel(string content, Point point)
60 | {
61 | _addLabelAction?.Invoke(content,point);
62 | }
63 |
64 | public void WhenReversePolygon(Action reverseActionCommand)
65 | {
66 | _reverseAction = reverseActionCommand;
67 | }
68 |
69 | public void ReversePolygon()
70 | {
71 | _reverseAction?.Invoke();
72 | }
73 | }
74 |
75 | public class Counter
76 | {
77 | private static Counter _counter;
78 | private static readonly object CreationLock = new object();
79 |
80 | public static Counter Default
81 | {
82 | get
83 | {
84 |
85 | if (_counter == null)
86 | {
87 | lock (CreationLock)
88 | {
89 | if (_counter == null)
90 | _counter = new Counter();
91 | }
92 | }
93 | return _counter;
94 | }
95 | }
96 |
97 | public int Val { get; set; } = 1;
98 |
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/ArbitraryPolygonCut/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/GraphicAlgorithm/Doc/示意图.vsd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/GraphicAlgorithm/Doc/示意图.vsd
--------------------------------------------------------------------------------
/GraphicAlgorithm/GraphicAlgorithm.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Doc", "Doc", "{06E260AB-290A-4C0E-984C-CF7B9D4C74D5}"
7 | ProjectSection(SolutionItems) = preProject
8 | Doc\示意图.vsd = Doc\示意图.vsd
9 | EndProjectSection
10 | EndProject
11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArbitraryPolygonCut", "ArbitraryPolygonCut\ArbitraryPolygonCut.csproj", "{2948D2A6-F19E-4DBF-A7F8-EA5BF96DFAEF}"
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {2948D2A6-F19E-4DBF-A7F8-EA5BF96DFAEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {2948D2A6-F19E-4DBF-A7F8-EA5BF96DFAEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {2948D2A6-F19E-4DBF-A7F8-EA5BF96DFAEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {2948D2A6-F19E-4DBF-A7F8-EA5BF96DFAEF}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | EndGlobal
28 |
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26228.12
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HadoopNET", "HadoopNET\HadoopNET.csproj", "{023B23D6-41F7-455A-92EF-E954AEE8A9DC}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubmitNet", "SubmitNet\SubmitNet.csproj", "{1AE5CC81-4BDA-40D0-ACC7-F191DA9358CA}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetReducer", "NetReducer\NetReducer.csproj", "{9C6BF11A-0159-4FAC-AF2F-09C67A0EEDC9}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMapper", "NetMapper\NetMapper.csproj", "{AF326F52-E4F8-46D2-9D8D-9F5AB3734C9A}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreReducer", "NetCoreReducer\NetCoreReducer.csproj", "{C4CB6499-D014-4529-B1CA-BB56F0E73162}"
15 | EndProject
16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreMapper", "NetCoreMapper\NetCoreMapper.csproj", "{FB8A5414-4B7E-4180-B047-1866C3BDC093}"
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetCreateCluster", "NetCreateCluster\NetCreateCluster.csproj", "{17FCC3A3-8D4B-40AE-8460-99BF7E771107}"
19 | EndProject
20 | Global
21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
22 | Debug|Any CPU = Debug|Any CPU
23 | Release|Any CPU = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
26 | {023B23D6-41F7-455A-92EF-E954AEE8A9DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {023B23D6-41F7-455A-92EF-E954AEE8A9DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {023B23D6-41F7-455A-92EF-E954AEE8A9DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {023B23D6-41F7-455A-92EF-E954AEE8A9DC}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {1AE5CC81-4BDA-40D0-ACC7-F191DA9358CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {1AE5CC81-4BDA-40D0-ACC7-F191DA9358CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {1AE5CC81-4BDA-40D0-ACC7-F191DA9358CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {1AE5CC81-4BDA-40D0-ACC7-F191DA9358CA}.Release|Any CPU.Build.0 = Release|Any CPU
34 | {9C6BF11A-0159-4FAC-AF2F-09C67A0EEDC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35 | {9C6BF11A-0159-4FAC-AF2F-09C67A0EEDC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
36 | {9C6BF11A-0159-4FAC-AF2F-09C67A0EEDC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
37 | {9C6BF11A-0159-4FAC-AF2F-09C67A0EEDC9}.Release|Any CPU.Build.0 = Release|Any CPU
38 | {AF326F52-E4F8-46D2-9D8D-9F5AB3734C9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39 | {AF326F52-E4F8-46D2-9D8D-9F5AB3734C9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
40 | {AF326F52-E4F8-46D2-9D8D-9F5AB3734C9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
41 | {AF326F52-E4F8-46D2-9D8D-9F5AB3734C9A}.Release|Any CPU.Build.0 = Release|Any CPU
42 | {C4CB6499-D014-4529-B1CA-BB56F0E73162}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43 | {C4CB6499-D014-4529-B1CA-BB56F0E73162}.Debug|Any CPU.Build.0 = Debug|Any CPU
44 | {C4CB6499-D014-4529-B1CA-BB56F0E73162}.Release|Any CPU.ActiveCfg = Release|Any CPU
45 | {C4CB6499-D014-4529-B1CA-BB56F0E73162}.Release|Any CPU.Build.0 = Release|Any CPU
46 | {FB8A5414-4B7E-4180-B047-1866C3BDC093}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
47 | {FB8A5414-4B7E-4180-B047-1866C3BDC093}.Debug|Any CPU.Build.0 = Debug|Any CPU
48 | {FB8A5414-4B7E-4180-B047-1866C3BDC093}.Release|Any CPU.ActiveCfg = Release|Any CPU
49 | {FB8A5414-4B7E-4180-B047-1866C3BDC093}.Release|Any CPU.Build.0 = Release|Any CPU
50 | {17FCC3A3-8D4B-40AE-8460-99BF7E771107}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51 | {17FCC3A3-8D4B-40AE-8460-99BF7E771107}.Debug|Any CPU.Build.0 = Debug|Any CPU
52 | {17FCC3A3-8D4B-40AE-8460-99BF7E771107}.Release|Any CPU.ActiveCfg = Release|Any CPU
53 | {17FCC3A3-8D4B-40AE-8460-99BF7E771107}.Release|Any CPU.Build.0 = Release|Any CPU
54 | EndGlobalSection
55 | GlobalSection(SolutionProperties) = preSolution
56 | HideSolutionNode = FALSE
57 | EndGlobalSection
58 | EndGlobal
59 |
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/HadoopNET.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {023B23D6-41F7-455A-92EF-E954AEE8A9DC}
8 | Exe
9 | Properties
10 | HadoopNET
11 | HadoopNET
12 | v4.6.1
13 | 512
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 | ..\packages\Microsoft.Hadoop.MapReduce.0.12.5807.28193\lib\net40\Microsoft.Hadoop.Client.dll
38 | True
39 |
40 |
41 | ..\packages\Microsoft.Hadoop.MapReduce.0.12.5807.28193\lib\net40\Microsoft.Hadoop.MapReduce.dll
42 | True
43 |
44 |
45 | ..\packages\Microsoft.Hadoop.MapReduce.0.12.5807.28193\lib\net40\Microsoft.Hadoop.WebClient.dll
46 | True
47 |
48 |
49 | ..\packages\Microsoft.Hadoop.MapReduce.0.12.5807.28193\lib\net40\Microsoft.WindowsAzure.Management.Framework.dll
50 | True
51 |
52 |
53 | ..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll
54 | True
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | Always
76 |
77 |
78 | Always
79 |
80 |
81 | Always
82 |
83 |
84 | Always
85 |
86 |
87 | Always
88 |
89 |
90 | Always
91 |
92 |
93 | Always
94 |
95 |
96 |
97 |
104 |
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/MRLib/MRRunner.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/HadoopNET/HadoopNET/MRLib/MRRunner.exe
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.Client.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.Client.dll
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.CombineDriver.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.CombineDriver.exe
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.MapDriver.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.MapDriver.exe
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.MapReduce.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.MapReduce.dll
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.ReduceDriver.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/HadoopNET/HadoopNET/MRLib/Microsoft.Hadoop.ReduceDriver.exe
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/MRLib/Microsoft.WindowsAzure.Management.Framework.Threading.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/HadoopNET/HadoopNET/MRLib/Microsoft.WindowsAzure.Management.Framework.Threading.dll
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.Hadoop.MapReduce;
7 |
8 | namespace HadoopNET
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 |
15 | var hadoop = Hadoop.Connect();
16 | hadoop.MapReduceJob.ExecuteJob();
17 | }
18 | }
19 |
20 | public class FirstMapper : MapperBase
21 | {
22 | public override void Map(string inputLine, MapperContext context)
23 | {
24 | // 输入
25 | int inputValue = int.Parse(inputLine);
26 |
27 | // 任务
28 | var sqrt = Math.Sqrt(inputValue);
29 |
30 | // 写入输出
31 | context.EmitKeyValue(inputValue.ToString(), sqrt.ToString());
32 | }
33 | }
34 |
35 | public class FirstJob : HadoopJob
36 | {
37 | public override HadoopJobConfiguration Configure(ExecutorContext context)
38 | {
39 | HadoopJobConfiguration config = new HadoopJobConfiguration();
40 | config.InputPath = "input/SqrtJob";
41 | config.OutputFolder = "output/SqrtJob";
42 | //config
43 | return config;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("HadoopNET")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("HadoopNET")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | //将 ComVisible 设置为 false 将使此程序集中的类型
18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("023b23d6-41f7-455a-92ef-e954aee8a9dc")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/HadoopNET/HadoopNET/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/HadoopNET/NetCoreMapper/NetCoreMapper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp1.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/HadoopNET/NetCoreMapper/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetCoreMapper
8 | {
9 | public class Program
10 | {
11 | public static void Main(string[] args)
12 | {
13 | if (args.Length > 0)
14 | {
15 | Stream stream = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.Read);
16 | Console.SetIn(new StreamReader(stream));
17 | }
18 |
19 | string line;
20 | while ((line = Console.ReadLine()) != null)
21 | {
22 | Console.WriteLine(line);
23 | }
24 |
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/HadoopNET/NetCoreMapper/publish.bat:
--------------------------------------------------------------------------------
1 | dotnet publish --framework netcoreapp1.0 --configuration release --output publish
--------------------------------------------------------------------------------
/HadoopNET/NetCoreReducer/NetCoreReducer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp1.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/HadoopNET/NetCoreReducer/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace NetCoreReducer
8 | {
9 | public class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | ILoggerFactory loggerFactory = new LoggerFactory()
14 | .AddConsole()
15 | .AddDebug();
16 | ILogger logger = loggerFactory.CreateLogger();
17 | logger.LogInformation(
18 | "This is a test of the emergency broadcast system.");
19 |
20 | string line;
21 | var count = 0;
22 |
23 | if (args.Length > 0)
24 | {
25 | Console.SetIn(new StreamReader(new FileStream(args[0], FileMode.Open, FileAccess.Read)));
26 | }
27 |
28 | while ((line = Console.ReadLine()) != null)
29 | {
30 | count += line.Count(cr => (cr == ' ' || cr == '\n'));
31 | }
32 | Console.WriteLine(count);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/HadoopNET/NetCoreReducer/publish.bat:
--------------------------------------------------------------------------------
1 | dotnet publish --framework netcoreapp1.0 --configuration release --output publish
--------------------------------------------------------------------------------
/HadoopNET/NetCreateCluster/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HadoopNET/NetCreateCluster/DeploymentHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.Azure.Management.ResourceManager;
8 | using Microsoft.Azure.Management.ResourceManager.Models;
9 | using Microsoft.Rest.Azure.Authentication;
10 | using Newtonsoft.Json;
11 | using Newtonsoft.Json.Linq;
12 |
13 | namespace NetCreateCluster
14 | {
15 | class DeploymentHelper
16 | {
17 | string subscriptionId = "";
18 | string clientId = "";
19 | string clientSecret = "";
20 | string resourceGroupName = "";
21 | string deploymentName = "";//这个是部署的名字而不是集群的名字,集群的名字是在模板指定的
22 | string resourceGroupLocation = ""; // 如果是创建新的资源组则需要指定,否则不需要
23 | string pathToTemplateFile = "template.json";
24 | string pathToParameterFile = "parameters.json";
25 | string tenantId = "";
26 |
27 | public async void Run()
28 | {
29 | // Try to obtain the service credentials
30 | var serviceCreds = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret);
31 |
32 | // Read the template and parameter file contents
33 | JObject templateFileContents = GetJsonFileContents(pathToTemplateFile);
34 | JObject parameterFileContents = GetJsonFileContents(pathToParameterFile);
35 |
36 | // Create the resource manager client
37 | var resourceManagementClient = new ResourceManagementClient(serviceCreds);
38 | resourceManagementClient.SubscriptionId = subscriptionId;
39 |
40 | // Create or check that resource group exists
41 | EnsureResourceGroupExists(resourceManagementClient, resourceGroupName, resourceGroupLocation);
42 |
43 | // Start a deployment
44 | DeployTemplate(resourceManagementClient, resourceGroupName, deploymentName, templateFileContents, parameterFileContents);
45 | }
46 |
47 | ///
48 | /// Reads a JSON file from the specified path
49 | ///
50 | /// The full path to the JSON file
51 | /// The JSON file contents
52 | private JObject GetJsonFileContents(string pathToJson)
53 | {
54 | JObject templatefileContent = new JObject();
55 | using (StreamReader file = File.OpenText(pathToJson))
56 | {
57 | using (JsonTextReader reader = new JsonTextReader(file))
58 | {
59 | templatefileContent = (JObject)JToken.ReadFrom(reader);
60 | return templatefileContent;
61 | }
62 | }
63 | }
64 |
65 | ///
66 | /// Ensures that a resource group with the specified name exists. If it does not, will attempt to create one.
67 | ///
68 | /// The resource manager client.
69 | /// The name of the resource group.
70 | /// The resource group location. Required when creating a new resource group.
71 | private static void EnsureResourceGroupExists(ResourceManagementClient resourceManagementClient, string resourceGroupName, string resourceGroupLocation)
72 | {
73 | if (resourceManagementClient.ResourceGroups.CheckExistence(resourceGroupName) != true)
74 | {
75 | Console.WriteLine(string.Format("Creating resource group '{0}' in location '{1}'", resourceGroupName, resourceGroupLocation));
76 | var resourceGroup = new ResourceGroup();
77 | resourceGroup.Location = resourceGroupLocation;
78 | resourceManagementClient.ResourceGroups.CreateOrUpdate(resourceGroupName, resourceGroup);
79 | }
80 | else
81 | {
82 | Console.WriteLine(string.Format("Using existing resource group '{0}'", resourceGroupName));
83 | }
84 | }
85 |
86 | ///
87 | /// Starts a template deployment.
88 | ///
89 | /// The resource manager client.
90 | /// The name of the resource group.
91 | /// The name of the deployment.
92 | /// The template file contents.
93 | /// The parameter file contents.
94 | private static void DeployTemplate(ResourceManagementClient resourceManagementClient, string resourceGroupName, string deploymentName, JObject templateFileContents, JObject parameterFileContents)
95 | {
96 | Console.WriteLine(
97 | $"Starting template deployment '{deploymentName}' in resource group '{resourceGroupName}'");
98 | var deployment = new Deployment();
99 |
100 | deployment.Properties = new DeploymentProperties
101 | {
102 | Mode = DeploymentMode.Incremental,
103 | Template = templateFileContents,
104 | Parameters = parameterFileContents["parameters"].ToObject()
105 | };
106 |
107 | var deploymentResult = resourceManagementClient.Deployments.CreateOrUpdate(resourceGroupName, deploymentName, deployment);
108 | Console.WriteLine($"Deployment status: {deploymentResult.Properties.ProvisioningState}");
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/HadoopNET/NetCreateCluster/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace NetCreateCluster
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | var helper = new DeploymentHelper();
10 | helper.Run();
11 |
12 | Console.ReadLine();//防止退出
13 | }
14 | }
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/HadoopNET/NetCreateCluster/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("NetCreateCluster")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("NetCreateCluster")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("17fcc3a3-8d4b-40ae-8460-99bf7e771107")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/HadoopNET/NetCreateCluster/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/HadoopNET/NetCreateCluster/parameters.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
3 | "contentVersion": "1.0.0.0",
4 | "parameters": {
5 | "clusterName": {
6 | "value": ""
7 | },
8 | "clusterLoginUserName": {
9 | "value": "admin"
10 | },
11 | "clusterLoginPassword": {
12 | "value": ""
13 | },
14 | "location": {
15 | "value": "eastasia"
16 | },
17 | "clusterWorkerNodeCount": {
18 | "value": 1
19 | },
20 | "clusterKind": {
21 | "value": "HADOOP"
22 | },
23 | "clusterVersion": {
24 | "value": "3.5"
25 | },
26 | "sshUserName": {
27 | "value": "sshuser"
28 | },
29 | "sshPassword": {
30 | "value": ""
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/HadoopNET/NetMapper/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HadoopNET/NetMapper/NetMapper.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {AF326F52-E4F8-46D2-9D8D-9F5AB3734C9A}
8 | Exe
9 | Properties
10 | NetMapper
11 | NetMapper
12 | v4.6.1
13 | 512
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
60 |
--------------------------------------------------------------------------------
/HadoopNET/NetMapper/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace NetMapper
5 | {
6 | class Cat
7 | {
8 | static void Main(string[] args)
9 | {
10 | if (args.Length > 0)
11 | {
12 | Console.SetIn(new StreamReader(args[0]));
13 | }
14 |
15 | string line;
16 | while ((line = Console.ReadLine()) != null)
17 | {
18 | Console.WriteLine(line);
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/HadoopNET/NetMapper/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("NetMap")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("NetMap")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | //将 ComVisible 设置为 false 将使此程序集中的类型
18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("af326f52-e4f8-46d2-9d8d-9f5ab3734c9a")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/HadoopNET/NetReducer/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HadoopNET/NetReducer/NetReducer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {9C6BF11A-0159-4FAC-AF2F-09C67A0EEDC9}
8 | Exe
9 | Properties
10 | NetReducer
11 | NetReducer
12 | v4.5.2
13 | 512
14 | true
15 |
16 |
17 | AnyCPU
18 | true
19 | full
20 | false
21 | bin\Debug\
22 | DEBUG;TRACE
23 | prompt
24 | 4
25 |
26 |
27 | AnyCPU
28 | pdbonly
29 | true
30 | bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
60 |
--------------------------------------------------------------------------------
/HadoopNET/NetReducer/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace NetReducer
9 | {
10 | class Program
11 | {
12 | private class Wc
13 | {
14 | static void Main(string[] args)
15 | {
16 | string line;
17 | var count = 0;
18 |
19 | if (args.Length > 0)
20 | {
21 | Console.SetIn(new StreamReader(args[0]));
22 | }
23 |
24 | while ((line = Console.ReadLine()) != null)
25 | {
26 | count += line.Count(cr => (cr == ' ' || cr == '\n'));
27 | }
28 | Console.WriteLine(count);
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/HadoopNET/NetReducer/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("NetReducer")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("NetReducer")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | //将 ComVisible 设置为 false 将使此程序集中的类型
18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("9c6bf11a-0159-4fac-af2f-09c67a0eedc9")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/HadoopNET/SubmitNet/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HadoopNET/SubmitNet/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using Hyak.Common;
9 | using Microsoft.Azure.Management.HDInsight.Job;
10 | using Microsoft.Azure.Management.HDInsight.Job.Models;
11 |
12 | namespace SubmitNet
13 | {
14 | class Program
15 | {
16 | private static HDInsightJobManagementClient _hdiJobManagementClient;
17 |
18 | private const string ExistingClusterUri = "xxx.azurehdinsight.net";
19 | private const string ExistingClusterUsername = "admin";
20 | private const string ExistingClusterPassword = "";
21 |
22 | private const string DefaultStorageAccountName = "";
23 | private const string DefaultStorageAccountKey = "";
24 | private const string DefaultStorageContainerName = "";
25 |
26 | static void Main(string[] args)
27 | {
28 | Console.WriteLine("The application is running ...");
29 |
30 | var clusterCredentials = new BasicAuthenticationCloudCredentials { Username = ExistingClusterUsername, Password = ExistingClusterPassword };
31 | _hdiJobManagementClient = new HDInsightJobManagementClient(ExistingClusterUri, clusterCredentials);
32 |
33 | SubmitMRJob();
34 |
35 | Console.WriteLine("Press ENTER to continue ...");
36 | Console.ReadLine();
37 | }
38 |
39 | private static void SubmitMRJob()
40 | {
41 | //var paras = new MapReduceStreamingJobSubmissionParameters
42 | //{
43 | // Files = new List() { "/example/app/.exe", "/example/apps/wc.exe" },
44 | // Mapper = "cat.exe",
45 | // Reducer = "wc.exe",
46 | // Input= "/example/data/gutenberg/davinci.txt",
47 | // Output = "/example/data/StreamingOutput/wc.txt"
48 | //};
49 |
50 | var paras = new MapReduceStreamingJobSubmissionParameters
51 | {
52 |
53 | Files = new List()
54 | {
55 | "/example/coreapp",
56 | },
57 | Mapper = "dotnet coreapp/NetCoreMapper.dll",
58 | Reducer = "dotnet coreapp/NetCoreReducer.dll",
59 | Input = "/example/data/gutenberg/davinci.txt",
60 | Output = "/example/data/StreamingOutput/wc.txt"
61 |
62 | };
63 |
64 | Console.WriteLine("Submitting the MR job to the cluster...");
65 | var jobResponse = _hdiJobManagementClient.JobManagement.SubmitMapReduceStreamingJob(paras);
66 | var jobId = jobResponse.JobSubmissionJsonResponse.Id;
67 | Console.WriteLine("Response status code is " + jobResponse.StatusCode);
68 | Console.WriteLine("JobId is " + jobId);
69 |
70 | Console.WriteLine("Waiting for the job completion ...");
71 |
72 | // Wait for job completion
73 | var jobDetail = _hdiJobManagementClient.JobManagement.GetJob(jobId).JobDetail;
74 | while (!jobDetail.Status.JobComplete)
75 | {
76 | Thread.Sleep(1000);
77 | jobDetail = _hdiJobManagementClient.JobManagement.GetJob(jobId).JobDetail;
78 | }
79 |
80 | // Get job output
81 | var storageAccess = new AzureStorageAccess(DefaultStorageAccountName, DefaultStorageAccountKey,
82 | DefaultStorageContainerName);
83 | var output = (jobDetail.ExitValue == 0)
84 | ? _hdiJobManagementClient.JobManagement.GetJobOutput(jobId, storageAccess) // fetch stdout output in case of success
85 | : _hdiJobManagementClient.JobManagement.GetJobErrorLogs(jobId, storageAccess); // fetch stderr output in case of failure
86 |
87 | Console.WriteLine("Job output is: ");
88 |
89 | using (var reader = new StreamReader(output, Encoding.UTF8))
90 | {
91 | string value = reader.ReadToEnd();
92 | Console.WriteLine(value);
93 | }
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/HadoopNET/SubmitNet/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("SubmitNet")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SubmitNet")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | //将 ComVisible 设置为 false 将使此程序集中的类型
18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("1ae5cc81-4bda-40d0-acc7-f191da9358ca")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/HadoopNET/SubmitNet/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/PCI/PCI.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26228.12
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PCI", "PCI\PCI.csproj", "{B1857D90-67F1-49DD-A5DB-B30163AB208F}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Debug|x64 = Debug|x64
12 | Release|Any CPU = Release|Any CPU
13 | Release|x64 = Release|x64
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {B1857D90-67F1-49DD-A5DB-B30163AB208F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {B1857D90-67F1-49DD-A5DB-B30163AB208F}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {B1857D90-67F1-49DD-A5DB-B30163AB208F}.Debug|x64.ActiveCfg = Debug|x64
19 | {B1857D90-67F1-49DD-A5DB-B30163AB208F}.Debug|x64.Build.0 = Debug|x64
20 | {B1857D90-67F1-49DD-A5DB-B30163AB208F}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {B1857D90-67F1-49DD-A5DB-B30163AB208F}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {B1857D90-67F1-49DD-A5DB-B30163AB208F}.Release|x64.ActiveCfg = Release|x64
23 | {B1857D90-67F1-49DD-A5DB-B30163AB208F}.Release|x64.Build.0 = Release|x64
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/PCI/PCI/App.config:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/PCI/PCI/Dorm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ConsoleApplication1
8 | {
9 | public class Dorm
10 | {
11 | // 宿舍,每个宿舍有两个隔间
12 | private List _dorms = new List()
13 | {
14 | "Zeus","Athena","Hercules","Bacchus","Pluto"
15 | };
16 |
17 | // 学生,以及首选和次选
18 | private List>> _prefs =
19 | new List>>()
20 | {
21 | Tuple.Create("Toby",Tuple.Create("Bacchus", "Hercules")),
22 | Tuple.Create("Steve",Tuple.Create("Zeus", "Pluto")),
23 | Tuple.Create("Andrea",Tuple.Create("Athena", "Zeus")),
24 | Tuple.Create("Sarah",Tuple.Create("Zeus", "Pluto")),
25 | Tuple.Create("Dave",Tuple.Create("Athena", "Bacchus")),
26 | Tuple.Create("Jeff",Tuple.Create("Hercules", "Pluto")),
27 | Tuple.Create("Fred",Tuple.Create("Pluto", "Athena")),
28 | Tuple.Create("Suzie",Tuple.Create("Bacchus", "Hercules")),
29 | Tuple.Create("Laura",Tuple.Create("Bacchus", "Hercules")),
30 | Tuple.Create("Neil",Tuple.Create("Hercules", "Athena"))
31 | };
32 |
33 | //题解范围
34 | public List> Domain =>
35 | Enumerable.Repeat(0, _dorms.Count*2)
36 | .Select((v, i) => Tuple.Create(0, _dorms.Count*2 - i - 1))
37 | .ToList();
38 |
39 | public void PrintSolution(List vec)
40 | {
41 | var slots = new List();
42 | // 为每个宿舍见两个槽
43 | for (int i = 0; i < _dorms.Count; i++)
44 | slots.AddRange(new []{i,i});
45 | // 遍历每一个名学生的安置情况
46 | for (int i = 0; i < vec.Count; i++)
47 | {
48 | var x = vec[i];
49 | //从剩余槽中选择
50 | var dorm = _dorms[slots[x]];
51 | //输出学生及其被分配的宿舍
52 | Console.WriteLine($"{_prefs[i].Item1} {dorm}");
53 | //删除该槽
54 | slots.RemoveAt(x);
55 | }
56 | }
57 |
58 | public float DormCost(List vec)
59 | {
60 | var cost = 0;
61 | // 建立槽序列
62 | var slots=new List() {0,0,1,1,2,2,3,3,4,4};
63 | // 遍历每一名学生
64 | for (int i = 0; i < vec.Count; i++)
65 | {
66 | var x = vec[i];
67 | var dorm = _dorms[slots[x]];
68 | var pref = _prefs[i].Item2;
69 | //首选成本为0,次选成本值为1
70 | //不在选择之列,成本加3
71 | if (pref.Item1 == dorm) cost += 0;
72 | else if (pref.Item2 == dorm) cost += 1;
73 | else cost += 3;
74 | //删除该槽
75 | slots.RemoveAt(x);
76 | }
77 | return cost;
78 | }
79 |
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/PCI/PCI/IClassifier.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data;
4 | using System.Data.Common;
5 | using System.Linq;
6 | using Dapper;
7 |
8 | namespace ConsoleApplication1
9 | {
10 | public interface IClassifier
11 | {
12 | int CatCount(Cat cat);
13 | List Categories();
14 | int Fcount(string f, Cat cat);
15 | float Fprob(string f, Cat cat);
16 | void Incc(Cat cat);
17 | void Incf(string f, Cat cat);
18 | int TotalCount();
19 | void Train(string item, Cat cat);
20 | float WeightedProb(string f, Cat cat, Func prf, float weight = 1, float ap = 0.5F);
21 | }
22 |
23 | public class SqliteClassifier : IClassifier
24 | {
25 | private IDbConnection _connection;
26 |
27 | public SqliteClassifier(Func> getFeatures, string dbname)
28 | {
29 | _getFeatures = getFeatures;
30 | _connection = GetConn(dbname);
31 | SetDb();
32 | }
33 |
34 | public void SetDb()
35 | {
36 | _connection.Execute("create table if not exists fc(feature, category, count)");
37 | _connection.Execute("create table if not exists cc(category,count)");
38 | }
39 |
40 | public IDbConnection GetConn(string dbname)
41 | {
42 | DbProviderFactory fact = DbProviderFactories.GetFactory("System.Data.SQLite");
43 | DbConnection cnn = fact.CreateConnection();
44 | cnn.ConnectionString = $"Data Source={dbname}";
45 | cnn.Open();
46 | return cnn;
47 | }
48 |
49 | protected Func> _getFeatures;
50 |
51 | public void Incf(string f, Cat cat)
52 | {
53 | var count = Fcount(f, cat);
54 | _connection.Execute(count == 0
55 | ? $"insert into fc values ('{f}','{cat}', 1)"
56 | : $"update fc set count={count + 1} where feature='{f}' and category='{cat}'");
57 | }
58 |
59 | public int Fcount(string f, Cat cat)
60 | {
61 | var res = _connection.ExecuteScalar($"select count from fc where feature='{f}' and category='{cat}'");
62 | return res;
63 | }
64 |
65 | public void Incc(Cat cat)
66 | {
67 | var count = CatCount(cat);
68 | if (count == 0) _connection.Execute($"insert into cc values ('{cat}', 1)");
69 | else _connection.Execute($"update cc set count={count + 1} where category='{cat}'");
70 | }
71 |
72 | public int CatCount(Cat cat)
73 | {
74 | var res = _connection.ExecuteScalar($"select count from cc where category='{cat}'");
75 | return res;
76 | }
77 |
78 | public List Categories()
79 | {
80 | return _connection.Query("select category from cc")
81 | .ToList()
82 | .Select(cs => Enum.Parse(typeof(Cat), cs))
83 | .Cast()
84 | .ToList();
85 | }
86 |
87 | public int TotalCount()
88 | {
89 | var res = _connection.ExecuteScalar("select sum(count) from cc");
90 | return res;
91 | }
92 |
93 | public void Train(string item, Cat cat)
94 | {
95 | var features = _getFeatures(item);
96 | //针对该分类为每个特征增加计数值
97 | foreach (var f in features)
98 | {
99 | Incf(f.Key, cat);
100 | }
101 |
102 | //增加针对该分类的计数值
103 | Incc(cat);
104 | }
105 |
106 | public float Fprob(string f, Cat cat)
107 | {
108 | if (CatCount(cat) == 0) return 0;
109 | // 特征在分类中出现的总次数,除以分类中包含的内容项总数
110 | return Fcount(f, cat) / (float)CatCount(cat);
111 | }
112 |
113 | public float WeightedProb(string f, Cat cat, Func prf, float weight = 1.0f, float ap = 0.5f)
114 | {
115 | // 计算当前概率
116 | var basicprob = prf(f, cat);
117 |
118 | // 特征(即单词)在所有分类中出现的次数
119 | var totals = Categories().Select(c => Fcount(f, c)).Sum();
120 |
121 | // 计算加权平均
122 | var bp = (weight * ap + totals * basicprob) / (weight + totals);
123 | return bp;
124 | }
125 | }
126 | }
--------------------------------------------------------------------------------
/PCI/PCI/ISimilar.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ConsoleApplication1
8 | {
9 | interface ISimilar
10 | {
11 | double Calc(Dictionary> prefs, string person1, string person2);
12 | }
13 |
14 | public class SimilarDistance : ISimilar
15 | {
16 | public double Calc(Dictionary> prefs, string person1, string person2)
17 | {
18 | //得到双方都评价过的电影列表
19 | var si = prefs[person1].Keys.Intersect(prefs[person2].Keys).ToList();
20 | if (!si.Any()) return 0;
21 | var sumSquares = si.Sum(s => Math.Pow(prefs[person1][s] - prefs[person2][s], 2));
22 | return 1 / (1 + Math.Sqrt(sumSquares));
23 | }
24 | }
25 |
26 | public class SimilarPerson : ISimilar
27 | {
28 | public double Calc(Dictionary> prefs, string person1, string person2)
29 | {
30 | //得到双方都评价过的电影列表
31 | var si = prefs[person1].Keys.Intersect(prefs[person2].Keys).ToList();
32 | if (!si.Any()) return -1;//没有共同之处,返回-1 (博主注,原文是返回1,感觉是个bug)
33 | //各种打分求和
34 | var sum1 = si.Sum(s => prefs[person1][s]);
35 | var sum2 = si.Sum(s => prefs[person2][s]);
36 | //打分的平方和
37 | var sum1Sq = si.Sum(s => Math.Pow(prefs[person1][s], 2));
38 | var sum2Sq = si.Sum(s => Math.Pow(prefs[person2][s], 2));
39 | //打分乘积之和
40 | var pSum = si.Sum(s => prefs[person1][s] * prefs[person2][s]);
41 | //计算皮尔逊评价值
42 | var num = pSum - (sum1 * sum2 / si.Count);
43 | var den = Math.Sqrt((sum1Sq - Math.Pow(sum1, 2) / si.Count) * (sum2Sq - Math.Pow(sum2, 2) / si.Count));
44 | if (den == 0) return 0;
45 | return num / den;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/PCI/PCI/LIBSVM_COPYRIGHT:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) 2000-2014 Chih-Chung Chang and Chih-Jen Lin
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions
7 | are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright
13 | notice, this list of conditions and the following disclaimer in the
14 | documentation and/or other materials provided with the distribution.
15 |
16 | 3. Neither name of copyright holders nor the names of its contributors
17 | may be used to endorse or promote products derived from this software
18 | without specific prior written permission.
19 |
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 |
--------------------------------------------------------------------------------
/PCI/PCI/Lib/Python.Runtime.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lsxqw2004/blog_sample_codes/7937834056439af865bd302dceaf4f949a5c9d06/PCI/PCI/Lib/Python.Runtime.dll
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/annotations.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plot
2 | from datetime import datetime
3 | from helpers import if_string_convert_to_datetime
4 |
5 |
6 | class Text:
7 | def __init__(self, jsonDict):
8 | self.fontSize = 12
9 | self.color = 'k'
10 | self.alpha = 1
11 | self.__dict__ = jsonDict
12 | self.x = if_string_convert_to_datetime(self.x)
13 |
14 | def plot(self, axes):
15 | plot.text(self.x,
16 | self.y,
17 | self.text,
18 | size=self.fontSize,
19 | alpha=self.alpha,
20 | color=self.color["value"])
21 |
22 |
23 | class Annotation:
24 | def __init__(self, jsonDict):
25 | self.fontSize = 12
26 | self.color = 'k'
27 | self.alpha = 1
28 | self.__dict__ = jsonDict
29 | self.x = if_string_convert_to_datetime(self.arrow_x)
30 | self.x = if_string_convert_to_datetime(self.text_x)
31 |
32 | def plot(self, axes):
33 | plot.annotate(self.text,
34 | xy=(self.arrow_x, self.arrow_y),
35 | xycoords='data',
36 | xytext=(self.text_x, self.text_y),
37 | textcoords='data',
38 | color=self.color["value"],
39 | size=self.fontSize,
40 | alpha=self.alpha,
41 | arrowprops=dict(
42 | linewidth=self.lineWidth,
43 | color=self.color["value"],
44 | alpha=self.alpha,
45 | arrowstyle=self.arrow_style,
46 | connectionstyle='arc3,rad=0',
47 | )
48 | )
49 |
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/arc.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plot
2 | import matplotlib.patches as patches
3 |
4 | from line_2d import Line2D
5 |
6 |
7 | class Arc(Line2D):
8 | def __init__(self, jsonDict):
9 | self.__dict__ = jsonDict
10 | self.check_if_x_is_time()
11 |
12 | def plot(self, axes):
13 | label = self.name if self.show_legend else ""
14 | a = patches.Arc((self.x, self.y),
15 | self.width,
16 | self.height,
17 | angle=self.angle,
18 | theta1=self.theta1,
19 | theta2=self.theta2,
20 | color=self.color["value"],
21 | linewidth=self.lineWidth,
22 | alpha=self.alpha,
23 | label=label)
24 | axes.add_patch(a)
25 | plot.hold(True)
26 |
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/helpers.py:
--------------------------------------------------------------------------------
1 | from datetime import datetime
2 |
3 |
4 | def if_string_convert_to_datetime(x):
5 | '''
6 | Checks if x is a string, then trying to convert it to datetime and return the result.
7 | If x is not a string, just returns the x itself
8 | :param self:
9 | :return:
10 | '''
11 |
12 | if isinstance(x, list):
13 | X = []
14 | for _x in x:
15 | X.append(if_string_convert_to_datetime(_x))
16 | return X
17 |
18 | if isinstance(x, str):
19 | # return datetime.strptime(x[0:19] + x[27:30] + x[31:33], '%Y-%m-%dT%H:%M:%S%z')
20 | # .net yyyy-MM-ddTHH:mm:ss,fff,zzz
21 | return datetime.strptime(x, '%Y-%m-%dT%H:%M:%S,%f')
22 | return x
23 |
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/histogram.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plot
2 | from matplotlib.ticker import FormatStrFormatter
3 |
4 |
5 | class Histogram:
6 | def __init__(self, jsonDict):
7 | self.__dict__ = jsonDict
8 |
9 | def plot(self, axes):
10 | label = self.name if self.show_legend else ""
11 | counts, bins, patches = plot.hist(
12 | self.y,
13 | self.bins,
14 | color=self.color["value"],
15 | normed=self.normed,
16 | orientation=self.orientation,
17 | range=self.range,
18 | cumulative=self.cumulative,
19 | histtype=self.histtype,
20 | alpha=self.alpha,
21 | label=label)
22 | plot.hold(True)
23 | axes.set_xticks(bins)
24 | # axes.xaxis.set_major_formatter(FormatStrFormatter('%f'))
25 |
26 |
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/hline.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plot
2 | from line_2d import Line2D
3 | from helpers import if_string_convert_to_datetime
4 |
5 | class Hline(Line2D):
6 | def __init__(self, jsonDict):
7 | self.__dict__ = jsonDict
8 | self.xmin = if_string_convert_to_datetime(self.xmin)
9 | self.xmax = if_string_convert_to_datetime(self.xmax)
10 |
11 | def plot(self, axes):
12 | label = self.name if self.show_legend else ""
13 | plot.hlines(self.y,
14 | self.xmin,
15 | self.xmax,
16 | color=self.color["value"],
17 | lw=self.lineWidth,
18 | linestyle=self.lineStyle,
19 | alpha=self.alpha,
20 | label=label)
21 | plot.hold(True)
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/line_2d.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plot
2 | from datetime import datetime
3 | import matplotlib.dates as mdates
4 | from helpers import if_string_convert_to_datetime
5 |
6 | class Line2D:
7 | def __init__(self, jsonDict):
8 | self.__dict__ = jsonDict
9 | self.check_if_x_is_time()
10 |
11 | def check_if_x_is_time(self):
12 | if isinstance(self.x, str) or (isinstance(self.x, list) and isinstance(self.x[0], str)):
13 | self.x = if_string_convert_to_datetime(self.x)
14 |
15 | def plot(self, axes):
16 | label = self.name if self.show_legend else ""
17 | markeredgecolor = self.color["value"] if self.markeredgecolor is None else self.markeredgecolor["value"]
18 | markerfacecolor = self.color["value"] if self.markerfacecolor is None else self.markerfacecolor["value"]
19 | plot.plot(self.x,
20 | self.y,
21 | color=self.color["value"],
22 | marker=self.marker,
23 | markeredgecolor=markeredgecolor,
24 | markeredgewidth=self.markeredgewidth,
25 | markerfacecolor=markerfacecolor,
26 | lw=self.lineWidth,
27 | ms=self.markerSize,
28 | ls=self.lineStyle,
29 | markevery=self.markevery,
30 | alpha=self.alpha,
31 | label=label)
32 | plot.hold(True)
33 |
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/subplot.py:
--------------------------------------------------------------------------------
1 | from annotations import Text, Annotation
2 | from arc import Arc
3 | from histogram import Histogram
4 | from hline import Hline
5 | from line_2d import Line2D
6 | from vline import Vline
7 |
8 |
9 | class Subplot:
10 | def __init__(self, jsonDict):
11 | self.index = 1
12 | self.title = ""
13 | self.xtitle = ""
14 | self.ytitle = ""
15 |
16 | self.__dict__ = jsonDict
17 |
18 | self.items = []
19 | if "__items__" in jsonDict:
20 | for item in jsonDict["__items__"]:
21 | if item["type"] == "Line2D":
22 | self.items.append(Line2D(item))
23 | elif item["type"] == "Point2D":
24 | self.items.append(Line2D(item))
25 | elif item["type"] == "Histogram":
26 | self.items.append(Histogram(item))
27 | elif item["type"] == "Text":
28 | self.items.append(Text(item))
29 | elif item["type"] == "Annotation":
30 | self.items.append(Annotation(item))
31 | elif item["type"] == "Hline":
32 | self.items.append(Hline(item))
33 | elif item["type"] == "Vline":
34 | self.items.append(Vline(item))
35 | elif item["type"] == "Arc":
36 | self.items.append(Arc(item))
37 |
38 | if "grid" in jsonDict:
39 | self.grid = Grid(jsonDict["grid"])
40 | else:
41 | self.grid = Grid()
42 |
43 |
44 | class Grid:
45 | def __init__(self, jsonDict):
46 | self.which = 'both'
47 | self.minor_alfa = 0.4
48 | self.major_alfa = 0.5
49 | self.on = 'on'
50 | self.__dict__ = jsonDict
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/task.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plot
2 |
3 | from line_2d import Line2D
4 | from subplot import Subplot
5 |
6 |
7 | class Task:
8 | def __init__(self, jsonDict):
9 | # set default values for most important properties
10 | self.dpi = 300
11 | self.w = 1920
12 | self.h = 1080
13 | self.rows = 1
14 | self.columns = 1
15 |
16 | # initialize object from json, received from c# process
17 | self.__dict__ = jsonDict
18 |
19 | self.subplots = []
20 | if "__subplots__" in jsonDict:
21 | for subplotJson in jsonDict["__subplots__"]:
22 | self.subplots.append(Subplot(subplotJson))
23 |
--------------------------------------------------------------------------------
/PCI/PCI/MatplotlibCS/vline.py:
--------------------------------------------------------------------------------
1 | import matplotlib.pyplot as plot
2 |
3 | from line_2d import Line2D
4 |
5 |
6 | class Vline(Line2D):
7 | def __init__(self, jsonDict):
8 | self.__dict__ = jsonDict
9 | self.check_if_x_is_time()
10 |
11 | def plot(self, axes):
12 | label = self.name if self.show_legend else ""
13 | plot.vlines(self.x,
14 | self.ymin,
15 | self.ymax,
16 | color=self.color["value"],
17 | lw=self.lineWidth,
18 | linestyle=self.lineStyle,
19 | alpha=self.alpha,
20 | label=label)
21 | plot.hold(True)
22 |
--------------------------------------------------------------------------------
/PCI/PCI/NewsFeaturesTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using ConsoleApplication1;
5 | using MathNet.Numerics.LinearAlgebra;
6 | using MathNet.Numerics.LinearAlgebra.Double;
7 | using Newtonsoft.Json;
8 | using PCI.pythonnet;
9 | using Python.Runtime;
10 | using Xunit;
11 | using Xunit.Abstractions;
12 |
13 | namespace PCI
14 | {
15 | public class NewsFeaturesTest
16 | {
17 | private readonly ITestOutputHelper _output;
18 |
19 | public NewsFeaturesTest(ITestOutputHelper output)
20 | {
21 | _output = output;
22 | }
23 |
24 | private void TestOutput(object obj)
25 | {
26 | _output.WriteLine(obj.ToString());
27 | }
28 |
29 | [Fact]
30 | public void TestMakeMatrix()
31 | {
32 | var newsFeatures = new NewsFeatures();
33 | (var allW,var artW,var artT) = newsFeatures.GetArticleWords();
34 | (var wordMatrix,var wordVec) = newsFeatures.MakeMatrix(allW, artW);
35 | // 单词向量的前10个词
36 | TestOutput(JsonConvert.SerializeObject(wordVec.Take(10)));
37 | // 第二篇文章的标题
38 | TestOutput(artT[1]);
39 | // 第二篇文章的在单词矩阵中对应的数据行的前10个值
40 | TestOutput(JsonConvert.SerializeObject(wordMatrix[1].Take(10)));
41 | }
42 |
43 | [Fact]
44 | public void TestMathNet()
45 | {
46 | // 测试矩阵乘法
47 | var m1 = DenseMatrix.OfArray(new[,] { { 1d, 2d, 3d }, { 4d, 5d, 6d } });
48 | TestOutput(m1);
49 | var m2 = DenseMatrix.OfArray(new[,] { { 1d, 2d }, { 3d, 4d }, { 5d, 6d } });
50 | TestOutput(m2);
51 | TestOutput((m1 * m2).ToString());
52 |
53 | //测试生成随机数组
54 | var mb = Matrix.Build;
55 | var rnd = new Random();
56 | var mr = mb.Dense(2, 3, (i, j) => rnd.NextDouble());
57 | TestOutput(mr);
58 |
59 | //测试矩阵转一维数组并由数组重构矩阵
60 | var arr = mr.AsColumnMajorArray();
61 | TestOutput(JsonConvert.SerializeObject(arr));
62 |
63 | var mback = mb.DenseOfColumnMajor(2, 3, arr);
64 | TestOutput(mback);
65 |
66 | //测试由行列表生成矩阵,并转换
67 | var rowList = new List>()
68 | {
69 | new List(){1, 2,3,4 },
70 | new List(){5,6,7,8 },
71 | new List(){9,10,11,12}
72 | };
73 | var matrixFromRow = mb.DenseOfRows(rowList);
74 | var matrixFromRowToColumnArr = matrixFromRow.AsColumnMajorArray();
75 | TestOutput(JsonConvert.SerializeObject(matrixFromRowToColumnArr));
76 | }
77 |
78 | [Fact]
79 | public void TestFactorize()
80 | {
81 | var m1 = DenseMatrix.OfArray(new[,] { { 1d, 2d, 3d }, { 4d, 5d, 6d } });
82 | var m2 = DenseMatrix.OfArray(new[,] { { 1d, 2d }, { 3d, 4d }, { 5d, 6d } });
83 | var m12 = m1 * m2;
84 | TestOutput(m12);
85 |
86 | var nmf = new Nmf(o => TestOutput(o.ToString()));
87 | (var w, var h) = nmf.Factorize(m12, 3, 100);
88 | TestOutput(w);
89 | TestOutput(h);
90 | TestOutput(w * h);
91 | }
92 |
93 | [Fact]
94 | public void TestArticleFactorize()
95 | {
96 | var newsFeatures = new NewsFeatures();
97 | (var allW, var artW, var artT) = newsFeatures.GetArticleWords();
98 | (var wordMatrix, var wordVec) = newsFeatures.MakeMatrix(allW, artW);
99 | var nmf = new Nmf(o => TestOutput(o.ToString()));
100 | var matrix = DenseMatrix.OfRows(wordMatrix);
101 | (var weights, var feat) = nmf.Factorize(matrix, 20, 50);
102 | TestOutput(weights);
103 | TestOutput(feat);
104 | }
105 |
106 | [Fact]
107 | public void TestShowFeatures()
108 | {
109 | var newsFeatures = new NewsFeatures();
110 | (var allW, var artW, var artT) = newsFeatures.GetArticleWords();
111 | (var wordMatrix, var wordVec) = newsFeatures.MakeMatrix(allW, artW);
112 | var nmf = new Nmf(o => TestOutput(o.ToString()));
113 | var matrix = DenseMatrix.OfRows(wordMatrix);
114 | (var weights, var feat) = nmf.Factorize(matrix, 20, 50);
115 | newsFeatures.ShowFeatures(weights, feat, artT, wordVec);
116 | }
117 |
118 | [Fact]
119 | public void TestShowArticles()
120 | {
121 | var newsFeatures = new NewsFeatures();
122 | (var allW, var artW, var artT) = newsFeatures.GetArticleWords();
123 | (var wordMatrix, var wordVec) = newsFeatures.MakeMatrix(allW, artW);
124 | var nmf = new Nmf(o => TestOutput(o.ToString()));
125 | var matrix = DenseMatrix.OfRows(wordMatrix);
126 | (var weights, var feat) = nmf.Factorize(matrix, 20, 50);
127 | (var topPatterns, var patternNames) = newsFeatures.ShowFeatures(weights, feat, artT, wordVec);
128 | newsFeatures.ShowArticles(artT, topPatterns, patternNames);
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/PCI/PCI/Nmf.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Forms;
7 | using MathNet.Numerics.LinearAlgebra;
8 | using MathNet.Numerics.LinearAlgebra.Double;
9 |
10 | namespace PCI
11 | {
12 | public class Nmf
13 | {
14 | private readonly Action