This repository was archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathAlchemyAPI_CombinedDataParams.cs
More file actions
185 lines (153 loc) · 4.29 KB
/
AlchemyAPI_CombinedDataParams.cs
File metadata and controls
185 lines (153 loc) · 4.29 KB
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
using System;
using System.Web;
namespace AlchemyAPI
{
///
/// Enumeration that specifies what to extract from the text.
/// Multiple extractions are specified via a bitmask.
///
/// e.g.
/// If you want to get title, author, and taxonomy, it would look like:
/// Extract::Title | Extract::Author | Extract::Taxonomy
///
public enum CombinedExtract
{
PageImage = 0x1,
Entity = 0x2,
Keyword = 0x4,
Title = 0x8,
Author = 0x10,
Taxonomy = 0x20,
Concept = 0x40,
Relation = 0x80,
DocSentiment = 0x100
};
public class AlchemyAPI_CombinedDataParams : AlchemyAPI_BaseParams
{
private PageImageMode? _imageMode;
private CombinedExtract _extract;
private string _jsonpCallback;
private bool? _disambiguateEntities;
private bool? _includeLinkedData;
private bool? _coreference;
private bool? _quotations;
private bool? _sentiment;
private bool? _showSourceText;
private int? _maxRetrieve;
private string _baseUrl;
public CombinedExtract Extractions {
get {
return _extract;
}
set {
_extract = value;
}
}
public PageImageMode? ImageMode {
get { return _imageMode; }
set { _imageMode = value; }
}
public string JsonPCallback {
get { return _jsonpCallback; }
set { _jsonpCallback = value; }
}
public bool? DisambiguateEntities {
get { return _disambiguateEntities; }
set { _disambiguateEntities = value; }
}
public bool? IncludeLinkedData {
get { return _includeLinkedData; }
set { _includeLinkedData = value; }
}
public bool? Coreference {
get { return _coreference; }
set { _coreference = value; }
}
public bool? Quotations {
get { return _quotations; }
set { _quotations = value; }
}
public bool? Sentiment {
get { return _sentiment; }
set { _sentiment = value; }
}
public bool? ShowSourceText {
get { return _showSourceText; }
set { _showSourceText = value; }
}
public int? MaxRetrieve {
get { return _maxRetrieve; }
set { _maxRetrieve = value; }
}
public string BaseURL {
get { return _baseUrl; }
set { _baseUrl = value; }
}
public bool isExtracting (CombinedExtract type)
{
return (_extract & type) == type;
}
public AlchemyAPI_CombinedDataParams setExtraction(CombinedExtract type, bool doExtraction)
{
if (doExtraction)
_extract |= type;
else
_extract &= ~type;
return this;
}
public override string getParameterString ()
{
string retString = base.getParameterString ();
retString += "&extract=" + getExtractionString();
if (_imageMode != null)
retString += "&extractMode=" + PageImageModeHelper.ToString(_imageMode.Value);
if (_jsonpCallback != null)
retString += "&jsonp=" + _jsonpCallback;
if (_disambiguateEntities != null)
retString += "&disambiguate=" + encodeBool(_disambiguateEntities);
if (_includeLinkedData != null)
retString += "&linkedData=" + encodeBool(_includeLinkedData);
if (_coreference != null)
retString += "&coreference=" + encodeBool(_coreference);
if (_quotations != null)
retString += ""ations=" + encodeBool(_quotations);
if (_sentiment != null)
retString += "&sentiment=" + encodeBool(_sentiment);
if (_showSourceText != null)
retString += "&showSourceText=" + encodeBool(_showSourceText);
if (_maxRetrieve != null)
retString += "&maxRetrieve=" + _maxRetrieve;
if (_baseUrl != null)
retString += "&baseUrl=" + _baseUrl;
return retString;
}
private string getExtractionString()
{
string ret = string.Empty;
if (isExtracting(CombinedExtract.PageImage))
ret += "page-image,";
if (isExtracting(CombinedExtract.Entity))
ret += "entity,";
if (isExtracting(CombinedExtract.Keyword))
ret += "keyword,";
if (isExtracting(CombinedExtract.Title))
ret += "title,";
if (isExtracting(CombinedExtract.Author))
ret += "author,";
if (isExtracting(CombinedExtract.Taxonomy))
ret += "taxonomy,";
if (isExtracting(CombinedExtract.Concept))
ret += "concept,";
if (isExtracting(CombinedExtract.Relation))
ret += "relation,";
if (isExtracting(CombinedExtract.DocSentiment))
ret += "doc-sentiment";
// Trim the trailing comma
if (ret.EndsWith(","))
ret = ret.Remove(ret.Length - 1);
if (ret.Length == 0)
throw new ArgumentException("At least one extraction must be specified.");
return ret;
}
}
}